@terreno/api 0.31.0 → 56.0.0-beta.0
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/CHANGELOG.md +122 -2
- package/LICENSE +202 -21
- package/dist/api.d.ts +12 -3
- package/dist/api.js +110 -361
- package/dist/auth.d.ts +26 -0
- package/dist/auth.js +100 -1
- package/dist/betterAuth.d.ts +5 -0
- package/dist/betterAuthSetup.d.ts +1 -15
- package/dist/betterAuthSetup.js +29 -8
- package/dist/configurationPlugin.js +2 -2
- package/dist/docLoader.js +12 -9
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +29 -1
- package/dist/expressServer.js +5 -11
- package/dist/githubAuth.js +4 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +29 -1
- package/dist/middleware.d.ts +7 -0
- package/dist/middleware.js +16 -1
- package/dist/openApiCompat.d.ts +10 -1
- package/dist/openApiCompat.js +115 -47
- package/dist/permissions.d.ts +27 -0
- package/dist/permissions.js +42 -1
- package/dist/plugins.d.ts +15 -3
- package/dist/plugins.js +36 -6
- package/dist/realtime/changeStreamWatcher.d.ts +100 -3
- package/dist/realtime/changeStreamWatcher.js +542 -137
- package/dist/realtime/realtimeApp.d.ts +3 -1
- package/dist/realtime/realtimeApp.js +75 -27
- package/dist/realtime/sessionRevalidation.d.ts +90 -0
- package/dist/realtime/sessionRevalidation.js +438 -0
- package/dist/realtime/socketAuth.d.ts +97 -0
- package/dist/realtime/socketAuth.js +272 -0
- package/dist/realtime/socketUser.d.ts +54 -0
- package/dist/realtime/socketUser.js +75 -5
- package/dist/realtime/types.d.ts +40 -0
- package/dist/secretProviders.d.ts +23 -0
- package/dist/secretProviders.js +9 -3
- package/dist/sync/executors.d.ts +198 -0
- package/dist/sync/executors.js +670 -0
- package/dist/sync/loadHarness.js +807 -0
- package/dist/sync/models.d.ts +216 -0
- package/dist/sync/models.js +644 -0
- package/dist/sync/mutationHandler.d.ts +97 -0
- package/dist/sync/mutationHandler.js +886 -0
- package/dist/sync/registry.d.ts +73 -0
- package/dist/sync/registry.js +223 -0
- package/dist/sync/routes.d.ts +62 -0
- package/dist/sync/routes.js +936 -0
- package/dist/sync/scripts/compactTombstones.d.ts +47 -0
- package/dist/sync/scripts/compactTombstones.js +270 -0
- package/dist/sync/serialize.d.ts +20 -0
- package/dist/{tests/bunSetup.js → sync/serialize.js} +35 -68
- package/dist/sync/socketHandlers.d.ts +54 -0
- package/dist/sync/socketHandlers.js +470 -0
- package/dist/sync/streams.d.ts +85 -0
- package/dist/sync/streams.js +221 -0
- package/dist/sync/syncApp.d.ts +29 -0
- package/dist/sync/syncApp.js +44 -0
- package/dist/sync/syncBatch.d.ts +71 -0
- package/dist/sync/syncBatch.js +252 -0
- package/dist/sync/syncSeqPlugin.d.ts +8 -0
- package/dist/sync/syncSeqPlugin.js +903 -0
- package/dist/sync/types.d.ts +254 -0
- package/dist/sync/types.js +9 -0
- package/dist/terrenoApp.js +90 -27
- package/dist/tests/models.d.ts +11 -27
- package/dist/tests/models.js +3 -5
- package/dist/tests/testHelper.d.ts +3 -9
- package/dist/vendor/wesleytodd-openapi/index.d.ts +1 -1
- package/dist/vendor/wesleytodd-openapi/lib/ui.d.ts +2 -1
- package/package.json +10 -8
- package/src/__tests__/openApiCompat.test.ts +20 -0
- package/src/actions.test.ts +12 -19
- package/src/actions.ts +2 -2
- package/src/api.coverage.test.ts +9 -7
- package/src/api.errorPaths.test.ts +1 -47
- package/src/api.test.ts +12 -0
- package/src/api.ts +98 -317
- package/src/auth.test.ts +128 -176
- package/src/auth.ts +109 -0
- package/src/betterAuth.ts +6 -0
- package/src/betterAuthSetup.test.ts +34 -0
- package/src/betterAuthSetup.ts +27 -8
- package/src/configurationPlugin.ts +2 -2
- package/src/consentApp.test.ts +12 -12
- package/src/docLoader.ts +3 -1
- package/src/errors.ts +33 -0
- package/src/expressServer.test.ts +7 -1
- package/src/expressServer.ts +5 -11
- package/src/githubAuth.ts +3 -1
- package/src/index.ts +42 -0
- package/src/middleware.test.ts +40 -1
- package/src/middleware.ts +15 -0
- package/src/models/versionConfig.ts +1 -1
- package/src/openApiBuilder.test.ts +9 -24
- package/src/openApiCompat.ts +99 -45
- package/src/openApiValidator.test.ts +0 -41
- package/src/permissions.test.ts +75 -1
- package/src/permissions.ts +49 -0
- package/src/plugins.test.ts +54 -14
- package/src/plugins.ts +47 -9
- package/src/populate.test.ts +16 -25
- package/src/realtime/changeStreamWatcher.ts +552 -114
- package/src/realtime/realtime.test.ts +157 -239
- package/src/realtime/realtimeApp.ts +80 -19
- package/src/realtime/sessionRevalidation.test.ts +423 -0
- package/src/realtime/sessionRevalidation.ts +273 -0
- package/src/realtime/socketAuth.test.ts +355 -0
- package/src/realtime/socketAuth.ts +228 -0
- package/src/realtime/socketUser.ts +69 -0
- package/src/realtime/types.ts +40 -0
- package/src/secretProviders.test.ts +7 -1
- package/src/secretProviders.ts +15 -3
- package/src/sync/ensureSyncIndexes.test.ts +144 -0
- package/src/sync/executors.test.ts +882 -0
- package/src/sync/executors.ts +703 -0
- package/src/sync/integration.test.ts +1160 -0
- package/src/sync/loadHarness.ts +618 -0
- package/src/sync/models.ts +640 -0
- package/src/sync/mutationHandler.test.ts +1252 -0
- package/src/sync/mutationHandler.ts +850 -0
- package/src/sync/registry.ts +232 -0
- package/src/sync/routes.ts +812 -0
- package/src/sync/scripts/compactTombstones.test.ts +249 -0
- package/src/sync/scripts/compactTombstones.ts +145 -0
- package/src/sync/serialize.ts +48 -0
- package/src/sync/sessionRevalidationIntegration.test.ts +281 -0
- package/src/sync/socketHandlers.ts +320 -0
- package/src/sync/streams.ts +188 -0
- package/src/sync/sync.test.ts +582 -0
- package/src/sync/syncApp.ts +44 -0
- package/src/sync/syncBatch.ts +219 -0
- package/src/sync/syncFrontier.test.ts +494 -0
- package/src/sync/syncPhaseC.test.ts +718 -0
- package/src/sync/syncRoutes.test.ts +865 -0
- package/src/sync/syncSeqPlugin.ts +738 -0
- package/src/sync/syncSocket.test.ts +1440 -0
- package/src/sync/types.ts +270 -0
- package/src/terrenoApp.ts +37 -17
- package/src/tests/bunSetup.ts +8 -0
- package/src/tests/models.ts +6 -8
- package/tsconfig.json +4 -4
- package/tsconfig.typedoc.json +7 -1
- package/dist/__tests__/openApiCompat.test.js +0 -317
- package/dist/__tests__/versionCheckPlugin.test.d.ts +0 -1
- package/dist/__tests__/versionCheckPlugin.test.js +0 -597
- package/dist/actions.openApi.test.d.ts +0 -1
- package/dist/actions.openApi.test.js +0 -253
- package/dist/actions.test.d.ts +0 -1
- package/dist/actions.test.js +0 -1087
- package/dist/api.arrayOperations.test.d.ts +0 -1
- package/dist/api.arrayOperations.test.js +0 -878
- package/dist/api.asyncHandler.test.d.ts +0 -1
- package/dist/api.asyncHandler.test.js +0 -236
- package/dist/api.coverage.test.d.ts +0 -1
- package/dist/api.coverage.test.js +0 -192
- package/dist/api.errorPaths.test.d.ts +0 -1
- package/dist/api.errorPaths.test.js +0 -887
- package/dist/api.errors.test.d.ts +0 -1
- package/dist/api.errors.test.js +0 -185
- package/dist/api.hooks.test.d.ts +0 -1
- package/dist/api.hooks.test.js +0 -950
- package/dist/api.query.test.d.ts +0 -1
- package/dist/api.query.test.js +0 -948
- package/dist/api.test.d.ts +0 -1
- package/dist/api.test.js +0 -2820
- package/dist/auth.compile.test.d.ts +0 -1
- package/dist/auth.compile.test.js +0 -201
- package/dist/auth.coverage.test.d.ts +0 -1
- package/dist/auth.coverage.test.js +0 -202
- package/dist/auth.test.d.ts +0 -1
- package/dist/auth.test.js +0 -2286
- package/dist/betterAuth.test.d.ts +0 -1
- package/dist/betterAuth.test.js +0 -181
- package/dist/betterAuthApp.test.d.ts +0 -1
- package/dist/betterAuthApp.test.js +0 -242
- package/dist/betterAuthSetup.test.d.ts +0 -1
- package/dist/betterAuthSetup.test.js +0 -762
- package/dist/config.test.d.ts +0 -1
- package/dist/config.test.js +0 -353
- package/dist/configuration.test.d.ts +0 -1
- package/dist/configuration.test.js +0 -980
- package/dist/configurationPlugin.test.d.ts +0 -1
- package/dist/configurationPlugin.test.js +0 -827
- package/dist/consentApp.test.d.ts +0 -1
- package/dist/consentApp.test.js +0 -1411
- package/dist/docLoader.test.d.ts +0 -1
- package/dist/docLoader.test.js +0 -137
- package/dist/envConfigurationPlugin.test.d.ts +0 -1
- package/dist/envConfigurationPlugin.test.js +0 -369
- package/dist/errors.test.d.ts +0 -1
- package/dist/errors.test.js +0 -607
- package/dist/expressServer.test.d.ts +0 -1
- package/dist/expressServer.test.js +0 -1249
- package/dist/githubAuth.test.d.ts +0 -1
- package/dist/githubAuth.test.js +0 -1142
- package/dist/httpClient.test.d.ts +0 -1
- package/dist/httpClient.test.js +0 -1471
- package/dist/logger.test.d.ts +0 -1
- package/dist/logger.test.js +0 -685
- package/dist/middleware.test.d.ts +0 -1
- package/dist/middleware.test.js +0 -241
- package/dist/notifiers/googleChatNotifier.test.d.ts +0 -1
- package/dist/notifiers/googleChatNotifier.test.js +0 -298
- package/dist/notifiers/slackNotifier.test.d.ts +0 -1
- package/dist/notifiers/slackNotifier.test.js +0 -297
- package/dist/notifiers/zoomNotifier.test.d.ts +0 -1
- package/dist/notifiers/zoomNotifier.test.js +0 -373
- package/dist/openApi.test.d.ts +0 -1
- package/dist/openApi.test.js +0 -620
- package/dist/openApiBuilder.test.d.ts +0 -1
- package/dist/openApiBuilder.test.js +0 -599
- package/dist/openApiEtag.test.d.ts +0 -1
- package/dist/openApiEtag.test.js +0 -86
- package/dist/openApiValidator.test.d.ts +0 -1
- package/dist/openApiValidator.test.js +0 -795
- package/dist/permissions.middleware.test.d.ts +0 -1
- package/dist/permissions.middleware.test.js +0 -308
- package/dist/permissions.test.d.ts +0 -1
- package/dist/permissions.test.js +0 -439
- package/dist/plugins.test.d.ts +0 -1
- package/dist/plugins.test.js +0 -902
- package/dist/populate.test.d.ts +0 -1
- package/dist/populate.test.js +0 -370
- package/dist/realtime/realtime.test.d.ts +0 -10
- package/dist/realtime/realtime.test.js +0 -4213
- package/dist/realtime/realtimeAppSetup.test.d.ts +0 -1
- package/dist/realtime/realtimeAppSetup.test.js +0 -213
- package/dist/requestContext.test.d.ts +0 -1
- package/dist/requestContext.test.js +0 -412
- package/dist/scriptRunner.test.d.ts +0 -1
- package/dist/scriptRunner.test.js +0 -386
- package/dist/secretProviders.test.d.ts +0 -1
- package/dist/secretProviders.test.js +0 -726
- package/dist/syncConsents.test.d.ts +0 -1
- package/dist/syncConsents.test.js +0 -522
- package/dist/terrenoApp.test.d.ts +0 -1
- package/dist/terrenoApp.test.js +0 -489
- package/dist/tests/bunSetup.d.ts +0 -1
- package/dist/tests/fixtures/compileAuthEntry.d.ts +0 -1
- package/dist/tests/fixtures/compileAuthEntry.js +0 -37
- package/dist/tests/testEnv.d.ts +0 -0
- package/dist/tests/testEnv.js +0 -6
- package/dist/transformers.test.d.ts +0 -1
- package/dist/transformers.test.js +0 -423
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -242
- package/src/realtime/realtimeAppSetup.test.ts +0 -161
- /package/dist/{__tests__/openApiCompat.test.d.ts → sync/loadHarness.d.ts} +0 -0
package/src/actions.test.ts
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
|
+
// noExplicitAny: test mock typing
|
|
2
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
1
3
|
import {beforeEach, describe, expect, it} from "bun:test";
|
|
2
4
|
import type express from "express";
|
|
3
|
-
import {type
|
|
5
|
+
import {type Model, model, Schema} from "mongoose";
|
|
4
6
|
import supertest from "supertest";
|
|
5
7
|
import type TestAgent from "supertest/lib/agent";
|
|
6
8
|
import {
|
|
7
9
|
ACTION_NAME_PATTERN,
|
|
8
|
-
type CollectionActionConfig,
|
|
9
10
|
createActionOpenApiMiddleware,
|
|
10
11
|
defineCollectionAction,
|
|
11
12
|
defineInstanceAction,
|
|
12
13
|
} from "./actions";
|
|
13
14
|
import {modelRouter, type OpenApiMiddleware} from "./api";
|
|
14
|
-
import {addAuthRoutes, setupAuth
|
|
15
|
+
import {addAuthRoutes, setupAuth} from "./auth";
|
|
15
16
|
import {apiUnauthorizedMiddleware} from "./errors";
|
|
16
17
|
import {Permissions} from "./permissions";
|
|
17
18
|
import {type IsDeleted, isDeletedPlugin} from "./plugins";
|
|
18
|
-
import {
|
|
19
|
-
authAsUser,
|
|
20
|
-
type Food,
|
|
21
|
-
FoodModel,
|
|
22
|
-
getBaseServer,
|
|
23
|
-
setupDb,
|
|
24
|
-
type User,
|
|
25
|
-
UserModel,
|
|
26
|
-
} from "./tests";
|
|
19
|
+
import {authAsUser, type Food, FoodModel, getBaseServer, setupDb, UserModel} from "./tests";
|
|
27
20
|
import {z} from "./zodOpenApi";
|
|
28
21
|
|
|
29
22
|
interface Stuff extends IsDeleted {
|
|
@@ -56,7 +49,7 @@ describe("modelRouter actions", () => {
|
|
|
56
49
|
broken: {
|
|
57
50
|
handler: async () => ({ok: true}),
|
|
58
51
|
method: "POST",
|
|
59
|
-
} as
|
|
52
|
+
} as any,
|
|
60
53
|
},
|
|
61
54
|
permissions: allPermissions,
|
|
62
55
|
})
|
|
@@ -149,8 +142,8 @@ describe("modelRouter actions", () => {
|
|
|
149
142
|
describe("integration", () => {
|
|
150
143
|
let app: express.Application;
|
|
151
144
|
let server: TestAgent;
|
|
152
|
-
let admin:
|
|
153
|
-
let notAdmin:
|
|
145
|
+
let admin: any;
|
|
146
|
+
let notAdmin: any;
|
|
154
147
|
let spinach: Food;
|
|
155
148
|
|
|
156
149
|
const mountFoodRouter = (options: Parameters<typeof modelRouter<Food>>[1]): void => {
|
|
@@ -181,8 +174,8 @@ describe("modelRouter actions", () => {
|
|
|
181
174
|
}),
|
|
182
175
|
]);
|
|
183
176
|
app = getBaseServer();
|
|
184
|
-
setupAuth(app, UserModel as
|
|
185
|
-
addAuthRoutes(app, UserModel as
|
|
177
|
+
setupAuth(app, UserModel as any);
|
|
178
|
+
addAuthRoutes(app, UserModel as any);
|
|
186
179
|
server = supertest(app);
|
|
187
180
|
});
|
|
188
181
|
|
|
@@ -291,8 +284,8 @@ describe("modelRouter actions", () => {
|
|
|
291
284
|
await StuffModel.deleteMany({});
|
|
292
285
|
const doc = await StuffModel.create({deleted: true, name: "hidden", ownerId: "1"});
|
|
293
286
|
app = getBaseServer();
|
|
294
|
-
setupAuth(app, UserModel as
|
|
295
|
-
addAuthRoutes(app, UserModel as
|
|
287
|
+
setupAuth(app, UserModel as any);
|
|
288
|
+
addAuthRoutes(app, UserModel as any);
|
|
296
289
|
app.use(
|
|
297
290
|
"/stuff",
|
|
298
291
|
modelRouter(StuffModel as Model<Stuff>, {
|
package/src/actions.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {OpenAPIRegistry, OpenApiGeneratorV3} from "@asteasolutions/zod-to-openapi";
|
|
2
2
|
import type express from "express";
|
|
3
3
|
import type {NextFunction, Request, Response} from "express";
|
|
4
|
-
import type {Model
|
|
4
|
+
import type {Model} from "mongoose";
|
|
5
5
|
import type {ZodSchema, ZodType} from "zod";
|
|
6
6
|
import {asyncHandler, type ModelRouterOptions, type RESTMethod} from "./api";
|
|
7
7
|
import {authenticateMiddleware, type User} from "./auth";
|
|
@@ -282,7 +282,7 @@ export const createActionOpenApiMiddleware = <T>({
|
|
|
282
282
|
};
|
|
283
283
|
|
|
284
284
|
const getArrayFieldNames = <T>(model: Model<T>): string[] => {
|
|
285
|
-
return
|
|
285
|
+
return Object.values(model.schema.paths)
|
|
286
286
|
.filter((config) => config.instance === "Array")
|
|
287
287
|
.map((config) => config.path);
|
|
288
288
|
};
|
package/src/api.coverage.test.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
// noExplicitAny: test mock typing
|
|
2
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
1
3
|
import {beforeEach, describe, expect, it} from "bun:test";
|
|
2
4
|
import type express from "express";
|
|
3
|
-
import mongoose
|
|
5
|
+
import mongoose from "mongoose";
|
|
4
6
|
import supertest from "supertest";
|
|
5
7
|
import type TestAgent from "supertest/lib/agent";
|
|
6
8
|
|
|
7
9
|
import {modelRouter} from "./api";
|
|
8
|
-
import {
|
|
10
|
+
import {addAuthRoutes, setupAuth} from "./auth";
|
|
9
11
|
import {Permissions} from "./permissions";
|
|
10
|
-
import {type Food, FoodModel, getBaseServer, setupDb,
|
|
12
|
+
import {type Food, FoodModel, getBaseServer, setupDb, UserModel} from "./tests";
|
|
11
13
|
|
|
12
14
|
// A model without the isDeleted plugin so deletes call doc.deleteOne(). The
|
|
13
15
|
// document delete hook throws to exercise the hard-delete error branch.
|
|
@@ -22,7 +24,7 @@ const ExplosiveModel = mongoose.model<{name: string}>("ExplosiveCoverage", explo
|
|
|
22
24
|
describe("modelRouter error path coverage", () => {
|
|
23
25
|
let server: TestAgent;
|
|
24
26
|
let app: express.Application;
|
|
25
|
-
let admin:
|
|
27
|
+
let admin: any;
|
|
26
28
|
let apple: Food;
|
|
27
29
|
|
|
28
30
|
beforeEach(async () => {
|
|
@@ -42,8 +44,8 @@ describe("modelRouter error path coverage", () => {
|
|
|
42
44
|
});
|
|
43
45
|
|
|
44
46
|
app = getBaseServer();
|
|
45
|
-
setupAuth(app, UserModel as
|
|
46
|
-
addAuthRoutes(app, UserModel as
|
|
47
|
+
setupAuth(app, UserModel as any);
|
|
48
|
+
addAuthRoutes(app, UserModel as any);
|
|
47
49
|
});
|
|
48
50
|
|
|
49
51
|
it("returns 400 when an array operation transformer throws a non-APIError", async () => {
|
|
@@ -102,7 +104,7 @@ describe("modelRouter error path coverage", () => {
|
|
|
102
104
|
const doc = await ExplosiveModel.create({name: "boom"});
|
|
103
105
|
app.use(
|
|
104
106
|
"/explosive",
|
|
105
|
-
modelRouter(ExplosiveModel, {
|
|
107
|
+
modelRouter(ExplosiveModel as any, {
|
|
106
108
|
allowAnonymous: true,
|
|
107
109
|
permissions: {
|
|
108
110
|
create: [Permissions.IsAny],
|
|
@@ -2,12 +2,11 @@ import {afterEach, beforeEach, describe, it, spyOn} from "bun:test";
|
|
|
2
2
|
import * as Sentry from "@sentry/bun";
|
|
3
3
|
import {assert} from "chai";
|
|
4
4
|
import type express from "express";
|
|
5
|
-
import {DateTime} from "luxon";
|
|
6
5
|
import mongoose from "mongoose";
|
|
7
6
|
import supertest from "supertest";
|
|
8
7
|
import type TestAgent from "supertest/lib/agent";
|
|
9
8
|
|
|
10
|
-
import {type
|
|
9
|
+
import {type ModelRouterOptions, modelRouter} from "./api";
|
|
11
10
|
import {addAuthRoutes, setupAuth} from "./auth";
|
|
12
11
|
import {ConflictError} from "./errors";
|
|
13
12
|
import {Permissions} from "./permissions";
|
|
@@ -193,51 +192,6 @@ describe("modelRouter error paths", () => {
|
|
|
193
192
|
saveSpy.mockRestore();
|
|
194
193
|
}
|
|
195
194
|
});
|
|
196
|
-
|
|
197
|
-
it("wraps failures while assembling the list response", async () => {
|
|
198
|
-
mountFood({
|
|
199
|
-
responseHandler: async (data) => {
|
|
200
|
-
const serialized = [...(data as Food[])] as Food[] & {slice: () => never};
|
|
201
|
-
serialized.slice = () => {
|
|
202
|
-
throw new Error("slice exploded");
|
|
203
|
-
};
|
|
204
|
-
return serialized as unknown as JSONValue;
|
|
205
|
-
},
|
|
206
|
-
});
|
|
207
|
-
const ownerId = new mongoose.Types.ObjectId();
|
|
208
|
-
await FoodModel.create([
|
|
209
|
-
{calories: 1, name: "First", ownerId},
|
|
210
|
-
{calories: 2, name: "Second", ownerId},
|
|
211
|
-
] as Partial<Food>[]);
|
|
212
|
-
|
|
213
|
-
// limit=1 fetches an extra doc, so the handler slices off the overflow.
|
|
214
|
-
const res = await server.get("/food?limit=1");
|
|
215
|
-
assert.equal(res.body.title, "Serialization error");
|
|
216
|
-
assert.include(res.body.detail, "slice exploded");
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("rejects a patch when the stored timestamp cannot be parsed", async () => {
|
|
220
|
-
// `updated` is a string here so the router has to parse it as an ISO date.
|
|
221
|
-
const timestampSchema = new mongoose.Schema({
|
|
222
|
-
name: {description: "The name", type: String},
|
|
223
|
-
updated: {description: "Last update, as an ISO string", type: String},
|
|
224
|
-
});
|
|
225
|
-
const TimestampModel = mongoose.model(`StringTimestamp_${Date.now()}`, timestampSchema);
|
|
226
|
-
app.use(
|
|
227
|
-
"/timestamped",
|
|
228
|
-
modelRouter(TimestampModel, {allowAnonymous: true, permissions: anyPermissions})
|
|
229
|
-
);
|
|
230
|
-
server = supertest(app);
|
|
231
|
-
|
|
232
|
-
const doc = await TimestampModel.create({name: "Timeless", updated: "not-a-date"});
|
|
233
|
-
|
|
234
|
-
const res = await server
|
|
235
|
-
.patch(`/timestamped/${doc._id}`)
|
|
236
|
-
.set("If-Unmodified-Since", DateTime.now().toHTTP() as string)
|
|
237
|
-
.send({name: "Renamed"})
|
|
238
|
-
.expect(400);
|
|
239
|
-
assert.equal(res.body.title, "Invalid server timestamp");
|
|
240
|
-
});
|
|
241
195
|
});
|
|
242
196
|
|
|
243
197
|
interface Guarded {
|
package/src/api.test.ts
CHANGED
|
@@ -1960,6 +1960,9 @@ describe("@terreno/api", () => {
|
|
|
1960
1960
|
|
|
1961
1961
|
it("returns 409 when If-Unmodified-Since is older than doc.updated", async () => {
|
|
1962
1962
|
const staleTimestamp = DateTime.fromISO("2025-06-15T11:00:00.000Z").toHTTP();
|
|
1963
|
+
if (staleTimestamp === null) {
|
|
1964
|
+
throw new Error("expected HTTP If-Unmodified-Since value");
|
|
1965
|
+
}
|
|
1963
1966
|
|
|
1964
1967
|
const res = await agent
|
|
1965
1968
|
.patch(`/food/${spinach._id}`)
|
|
@@ -1976,6 +1979,9 @@ describe("@terreno/api", () => {
|
|
|
1976
1979
|
|
|
1977
1980
|
it("succeeds when If-Unmodified-Since matches or is newer than doc.updated", async () => {
|
|
1978
1981
|
const freshTimestamp = DateTime.fromISO("2025-06-15T13:00:00.000Z").toHTTP();
|
|
1982
|
+
if (freshTimestamp === null) {
|
|
1983
|
+
throw new Error("expected HTTP If-Unmodified-Since value");
|
|
1984
|
+
}
|
|
1979
1985
|
|
|
1980
1986
|
const res = await agent
|
|
1981
1987
|
.patch(`/food/${spinach._id}`)
|
|
@@ -1997,6 +2003,9 @@ describe("@terreno/api", () => {
|
|
|
1997
2003
|
|
|
1998
2004
|
it("succeeds when If-Unmodified-Since exactly matches doc.updated", async () => {
|
|
1999
2005
|
const exactTimestamp = DateTime.fromISO("2025-06-15T12:00:00.000Z").toHTTP();
|
|
2006
|
+
if (exactTimestamp === null) {
|
|
2007
|
+
throw new Error("expected HTTP If-Unmodified-Since value");
|
|
2008
|
+
}
|
|
2000
2009
|
|
|
2001
2010
|
const res = await agent
|
|
2002
2011
|
.patch(`/food/${spinach._id}`)
|
|
@@ -2009,6 +2018,9 @@ describe("@terreno/api", () => {
|
|
|
2009
2018
|
|
|
2010
2019
|
it("prefers precise conflict timestamp header when present", async () => {
|
|
2011
2020
|
const roundedStaleTimestamp = DateTime.fromISO("2025-06-15T11:59:59.000Z").toHTTP();
|
|
2021
|
+
if (roundedStaleTimestamp === null) {
|
|
2022
|
+
throw new Error("expected HTTP If-Unmodified-Since value");
|
|
2023
|
+
}
|
|
2012
2024
|
|
|
2013
2025
|
const res = await agent
|
|
2014
2026
|
.patch(`/food/${spinach._id}`)
|