Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add threshold in DateProvider #242

Merged
merged 7 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundle/bundle.js

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions lib/build/claims/primitiveArrayClaim.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions lib/build/claims/primitiveClaim.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/fetch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/build/recipeImplementation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/build/utils/dateProvider/defaultImplementation.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion lib/build/utils/dateProvider/defaultImplementation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions lib/build/utils/dateProvider/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/build/utils/dateProvider/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 68 additions & 20 deletions lib/ts/claims/primitiveArrayClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,20 @@ export class PrimitiveArrayClaim<ValueType> {
return {
id: id !== undefined ? id : this.id,
refresh: ctx => this.refresh(ctx),
shouldRefresh: (payload, ctx) =>
this.getValueFromPayload(payload, ctx) === undefined ||
// We know payload[this.id] is defined since the value is not undefined in this branch
(maxAgeInSeconds !== undefined && payload[this.id].t < DateProvider.now() - maxAgeInSeconds * 1000),
shouldRefresh: (payload, ctx) => {
if (maxAgeInSeconds !== undefined && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
throw new Error(
`maxAgeInSeconds must be greater than or equal to the DateProvider threshold value -> ${DateProvider.getThresholdInSeconds()}`
);
}

return (
this.getValueFromPayload(payload, ctx) === undefined ||
// We know payload[this.id] is defined since the value is not undefined in this branch
(maxAgeInSeconds !== undefined &&
payload[this.id].t < DateProvider.now() - maxAgeInSeconds * 1000)
);
},
validate: async (payload, ctx) => {
const claimVal = this.getValueFromPayload(payload, ctx);
if (claimVal === undefined) {
Expand Down Expand Up @@ -78,10 +88,19 @@ export class PrimitiveArrayClaim<ValueType> {
return {
id: id !== undefined ? id : this.id,
refresh: ctx => this.refresh(ctx),
shouldRefresh: (payload, ctx) =>
this.getValueFromPayload(payload, ctx) === undefined ||
// We know payload[this.id] is defined since the value is not undefined in this branch
(maxAgeInSeconds !== undefined && payload[this.id].t < DateProvider.now() - maxAgeInSeconds * 1000),
shouldRefresh: (payload, ctx) => {
if (maxAgeInSeconds !== undefined && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
throw new Error(
`maxAgeInSeconds must be greater than or equal to the DateProvider threshold value -> ${DateProvider.getThresholdInSeconds()}`
);
}
return (
this.getValueFromPayload(payload, ctx) === undefined ||
// We know payload[this.id] is defined since the value is not undefined in this branch
(maxAgeInSeconds !== undefined &&
payload[this.id].t < DateProvider.now() - maxAgeInSeconds * 1000)
);
},
validate: async (payload, ctx) => {
const claimVal = this.getValueFromPayload(payload, ctx);
if (claimVal === undefined) {
Expand Down Expand Up @@ -124,10 +143,19 @@ export class PrimitiveArrayClaim<ValueType> {
return {
id: id !== undefined ? id : this.id,
refresh: ctx => this.refresh(ctx),
shouldRefresh: (payload, ctx) =>
this.getValueFromPayload(payload, ctx) === undefined ||
// We know payload[this.id] is defined since the value is not undefined in this branch
(maxAgeInSeconds !== undefined && payload[this.id].t < DateProvider.now() - maxAgeInSeconds * 1000),
shouldRefresh: (payload, ctx) => {
if (maxAgeInSeconds !== undefined && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
throw new Error(
`maxAgeInSeconds must be greater than or equal to the DateProvider threshold value -> ${DateProvider.getThresholdInSeconds()}`
);
}
return (
this.getValueFromPayload(payload, ctx) === undefined ||
// We know payload[this.id] is defined since the value is not undefined in this branch
(maxAgeInSeconds !== undefined &&
payload[this.id].t < DateProvider.now() - maxAgeInSeconds * 1000)
);
},
validate: async (payload, ctx) => {
const claimVal = this.getValueFromPayload(payload, ctx);
if (claimVal === undefined) {
Expand Down Expand Up @@ -167,10 +195,20 @@ export class PrimitiveArrayClaim<ValueType> {
return {
id: id !== undefined ? id : this.id,
refresh: ctx => this.refresh(ctx),
shouldRefresh: (payload, ctx) =>
this.getValueFromPayload(payload, ctx) === undefined ||
// We know payload[this.id] is defined since the value is not undefined in this branch
(maxAgeInSeconds !== undefined && payload[this.id].t < DateProvider.now() - maxAgeInSeconds * 1000),
shouldRefresh: (payload, ctx) => {
if (maxAgeInSeconds !== undefined && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
throw new Error(
`maxAgeInSeconds must be greater than or equal to the DateProvider threshold value -> ${DateProvider.getThresholdInSeconds()}`
);
}

return (
this.getValueFromPayload(payload, ctx) === undefined ||
// We know payload[this.id] is defined since the value is not undefined in this branch
(maxAgeInSeconds !== undefined &&
payload[this.id].t < DateProvider.now() - maxAgeInSeconds * 1000)
);
},
validate: async (payload, ctx) => {
const claimVal = this.getValueFromPayload(payload, ctx);
if (claimVal === undefined) {
Expand Down Expand Up @@ -214,10 +252,20 @@ export class PrimitiveArrayClaim<ValueType> {
return {
id: id !== undefined ? id : this.id,
refresh: ctx => this.refresh(ctx),
shouldRefresh: (payload, ctx) =>
this.getValueFromPayload(payload, ctx) === undefined ||
// We know payload[this.id] is defined since the value is not undefined in this branch
(maxAgeInSeconds !== undefined && payload[this.id].t < DateProvider.now() - maxAgeInSeconds * 1000),
shouldRefresh: (payload, ctx) => {
if (maxAgeInSeconds !== undefined && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) {
throw new Error(
`maxAgeInSeconds must be greater than or equal to the DateProvider threshold value -> ${DateProvider.getThresholdInSeconds()}`
);
}

return (
this.getValueFromPayload(payload, ctx) === undefined ||
// We know payload[this.id] is defined since the value is not undefined in this branch
(maxAgeInSeconds !== undefined &&
payload[this.id].t < DateProvider.now() - maxAgeInSeconds * 1000)
);
},
validate: async (payload, ctx) => {
const claimVal = this.getValueFromPayload(payload, ctx);
if (claimVal === undefined) {
Expand Down
Loading
Loading