@openstax/ts-utils 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/services/lrsGateway/file-system.js +17 -3
- package/dist/cjs/services/lrsGateway/index.d.ts +7 -1
- package/dist/cjs/services/lrsGateway/index.js +2 -2
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/services/lrsGateway/file-system.js +17 -3
- package/dist/esm/services/lrsGateway/index.d.ts +7 -1
- package/dist/esm/services/lrsGateway/index.js +2 -2
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -57,19 +57,33 @@ export const fileSystemLrsGateway = (initializer) => (configProvider) => (authPr
|
|
|
57
57
|
await save;
|
|
58
58
|
return statementsWithDefaults;
|
|
59
59
|
};
|
|
60
|
-
const getAllXapiStatements = async ({ user, anyUser, ...options }) => {
|
|
60
|
+
const getAllXapiStatements = async ({ user, anyUser, fetchUntil, ...options }) => {
|
|
61
61
|
const authUser = await authProvider.getUser();
|
|
62
62
|
await load;
|
|
63
|
-
|
|
63
|
+
let filteredData = (data || []).filter(statement => {
|
|
64
64
|
var _a, _b, _c, _d;
|
|
65
|
+
const statementDate = new Date(statement.timestamp);
|
|
66
|
+
const sinceDate = options.since ? new Date(options.since) : null;
|
|
67
|
+
const untilDate = options.until ? new Date(options.until) : null;
|
|
65
68
|
return (anyUser === true || statement.actor.account.name === (user || assertDefined(authUser, new UnauthorizedError()).uuid))
|
|
66
69
|
&& (!options.verb || statement.verb.id === options.verb)
|
|
67
70
|
&& (!options.registration || ((_a = statement.context) === null || _a === void 0 ? void 0 : _a.registration) === options.registration)
|
|
68
71
|
&& (!options.activity || (options.related_activities
|
|
69
72
|
? ((statement.object.id === options.activity && statement.object.objectType === 'Activity')
|
|
70
73
|
|| (!!((_d = (_c = (_b = statement.context) === null || _b === void 0 ? void 0 : _b.contextActivities) === null || _c === void 0 ? void 0 : _c.parent) === null || _d === void 0 ? void 0 : _d.find(parent => parent.id === options.activity && parent.objectType === 'Activity'))))
|
|
71
|
-
: (statement.object.id === options.activity && statement.object.objectType === 'Activity')))
|
|
74
|
+
: (statement.object.id === options.activity && statement.object.objectType === 'Activity')))
|
|
75
|
+
&& (!sinceDate || statementDate >= sinceDate)
|
|
76
|
+
&& (!untilDate || statementDate <= untilDate);
|
|
72
77
|
});
|
|
78
|
+
if (fetchUntil) {
|
|
79
|
+
for (let i = 0; i < filteredData.length; i += pageSize) {
|
|
80
|
+
if (fetchUntil(filteredData.slice(0, i + pageSize))) {
|
|
81
|
+
filteredData = filteredData.slice(0, i + pageSize);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return filteredData;
|
|
73
87
|
};
|
|
74
88
|
const getMoreXapiStatements = async (more) => {
|
|
75
89
|
const { args, offset } = JSON.parse(more);
|
|
@@ -90,6 +90,8 @@ export declare const lrsGateway: <C extends string = "lrs">(initializer: Initial
|
|
|
90
90
|
related_activities?: boolean | undefined;
|
|
91
91
|
user?: string | undefined;
|
|
92
92
|
anyUser?: boolean | undefined;
|
|
93
|
+
since?: string | undefined;
|
|
94
|
+
until?: string | undefined;
|
|
93
95
|
} & {
|
|
94
96
|
ensureSync?: boolean | undefined;
|
|
95
97
|
}) => Promise<{
|
|
@@ -100,15 +102,19 @@ export declare const lrsGateway: <C extends string = "lrs">(initializer: Initial
|
|
|
100
102
|
more: string;
|
|
101
103
|
statements: XapiStatement[];
|
|
102
104
|
}>;
|
|
103
|
-
getAllXapiStatements: (params: {
|
|
105
|
+
getAllXapiStatements: ({ fetchUntil, ...params }: {
|
|
104
106
|
verb?: string | undefined;
|
|
105
107
|
activity?: string | undefined;
|
|
106
108
|
registration?: string | undefined;
|
|
107
109
|
related_activities?: boolean | undefined;
|
|
108
110
|
user?: string | undefined;
|
|
109
111
|
anyUser?: boolean | undefined;
|
|
112
|
+
since?: string | undefined;
|
|
113
|
+
until?: string | undefined;
|
|
110
114
|
} & {
|
|
111
115
|
ensureSync?: boolean | undefined;
|
|
116
|
+
} & {
|
|
117
|
+
fetchUntil?: ((statements: XapiStatement[]) => boolean) | undefined;
|
|
112
118
|
}) => Promise<XapiStatement[]>;
|
|
113
119
|
};
|
|
114
120
|
export {};
|
|
@@ -94,9 +94,9 @@ ${await response.text()}`);
|
|
|
94
94
|
return formatGetXapiStatementsResponse(fetchXapiStatements(fetchParams));
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
|
-
const getAllXapiStatements = async (params) => {
|
|
97
|
+
const getAllXapiStatements = async ({ fetchUntil, ...params }) => {
|
|
98
98
|
const loadRemaining = async (result) => {
|
|
99
|
-
if (!result.more) {
|
|
99
|
+
if (!result.more || (fetchUntil && fetchUntil(result.statements))) {
|
|
100
100
|
return result.statements;
|
|
101
101
|
}
|
|
102
102
|
const { more, statements } = await getMoreXapiStatements(result.more);
|