@getstrata/core 3.0.8 → 3.1.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 +10 -877
- package/README.md +20 -57
- package/dist/core/database/definitions.d.ts +8 -2
- package/dist/core/database/driverPorts.d.ts +1 -1
- package/dist/core/database/index.d.ts +3 -2
- package/dist/core/database/model.d.ts +19 -4
- package/dist/core/database/modelAuthoring.d.ts +64 -0
- package/dist/core/database/modelRegistry.d.ts +5 -1
- package/dist/core/database/modelRelationTypes.d.ts +14 -0
- package/dist/core/database/ormInternal.d.ts +2 -1
- package/dist/core/database/ormRuntime.d.ts +2 -1
- package/dist/core/http/index.d.ts +2 -2
- package/dist/core/http/parseMultipartUpload.d.ts +1 -0
- package/dist/core/http/streamingUpload.d.ts +20 -0
- package/dist/core/http/uploadContent.d.ts +6 -0
- package/dist/core/media/imageTransform.d.ts +25 -1
- package/dist/entries/database/bindings.js +34 -11
- package/dist/entries/database/definitions.js +6 -0
- package/dist/entries/database/ownedReadOnlyObservation.js +3 -1
- package/dist/entries/http/parseMultipartUpload.js +408 -20
- package/dist/entries/media/imageTransform.js +110 -20
- package/dist/framework/public-api.d.ts +4 -3
- package/dist/index.js +70 -102
- package/dist/internal/ormRuntime.js +173 -9
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -59,8 +59,8 @@ import {
|
|
|
59
59
|
renderTransactionAcquisitionMetrics
|
|
60
60
|
} from "@getstrata/core/database/acquisitionMetrics";
|
|
61
61
|
import {
|
|
62
|
-
defineModel,
|
|
63
62
|
defineRepository as defineRepository2,
|
|
63
|
+
modelEffects,
|
|
64
64
|
repositoryEffects
|
|
65
65
|
} from "@getstrata/core/database/definitions";
|
|
66
66
|
import {
|
|
@@ -72,7 +72,7 @@ import {
|
|
|
72
72
|
import { defineFactory, Factory } from "@getstrata/core/database/factory";
|
|
73
73
|
import { DATABASE_SESSION_TOKEN as DATABASE_SESSION_TOKEN2 } from "@getstrata/core/database/tokens";
|
|
74
74
|
import {
|
|
75
|
-
BadRequestError as
|
|
75
|
+
BadRequestError as BadRequestError8,
|
|
76
76
|
ConflictError as ConflictError3,
|
|
77
77
|
ForbiddenError as ForbiddenError14,
|
|
78
78
|
HttpError as HttpError3,
|
|
@@ -80,13 +80,20 @@ import {
|
|
|
80
80
|
InvalidCredentialsError as InvalidCredentialsError3,
|
|
81
81
|
isHttpErrorLike,
|
|
82
82
|
NotFoundError as NotFoundError4,
|
|
83
|
-
PayloadTooLargeError as
|
|
83
|
+
PayloadTooLargeError as PayloadTooLargeError3,
|
|
84
84
|
PreconditionFailedError as PreconditionFailedError3,
|
|
85
85
|
toHttpError as toHttpError4,
|
|
86
86
|
UnauthorizedError as UnauthorizedError4,
|
|
87
87
|
UnprocessableEntityError as UnprocessableEntityError5,
|
|
88
88
|
ValidationError as ValidationError4
|
|
89
89
|
} from "@getstrata/core/errors/http";
|
|
90
|
+
import {
|
|
91
|
+
parseMultipartUpload as parseMultipartUpload2,
|
|
92
|
+
parseMultipartUploadStream as parseMultipartUploadStream2,
|
|
93
|
+
sanitizeUploadFileName as sanitizeUploadFileName2,
|
|
94
|
+
UploadedFile as UploadedFile2,
|
|
95
|
+
validateUploadFile as validateUploadFile2
|
|
96
|
+
} from "@getstrata/core/http/parseMultipartUpload";
|
|
90
97
|
import {
|
|
91
98
|
createIdentityQueue as createIdentityQueue2,
|
|
92
99
|
createQueueHandoff as createQueueHandoff2,
|
|
@@ -98,6 +105,8 @@ import {
|
|
|
98
105
|
BelongsToManyRelationQuery,
|
|
99
106
|
BelongsToRelationQuery,
|
|
100
107
|
createModel,
|
|
108
|
+
defineModel,
|
|
109
|
+
field,
|
|
101
110
|
HasManyRelationQuery,
|
|
102
111
|
HasManyThroughRelationQuery,
|
|
103
112
|
HasOneRelationQuery,
|
|
@@ -106,6 +115,7 @@ import {
|
|
|
106
115
|
MorphManyRelationQuery,
|
|
107
116
|
MorphOneRelationQuery,
|
|
108
117
|
MorphToRelationQuery,
|
|
118
|
+
modelTable,
|
|
109
119
|
RepositoryQuery as RepositoryQuery2
|
|
110
120
|
} from "#strata-orm-runtime";
|
|
111
121
|
|
|
@@ -4282,8 +4292,10 @@ import {
|
|
|
4282
4292
|
import {
|
|
4283
4293
|
BaseRepository as BaseRepository2,
|
|
4284
4294
|
createBoundModel,
|
|
4295
|
+
createClassModelDefinition,
|
|
4285
4296
|
getModelBinding,
|
|
4286
4297
|
getRepositoryBinding,
|
|
4298
|
+
isModelClass,
|
|
4287
4299
|
Model
|
|
4288
4300
|
} from "#strata-orm-runtime";
|
|
4289
4301
|
|
|
@@ -4422,7 +4434,19 @@ function definitionArray(values) {
|
|
|
4422
4434
|
}
|
|
4423
4435
|
function snapshotRegistry(repositories = [], models = [], repositoryEffects = []) {
|
|
4424
4436
|
repositories = definitionArray(repositories);
|
|
4425
|
-
|
|
4437
|
+
const classDefinitions = new Map;
|
|
4438
|
+
const implicitRepositories = [];
|
|
4439
|
+
const resolvedModels = definitionArray(models).map((model) => {
|
|
4440
|
+
if (!isModelClass(model))
|
|
4441
|
+
return model;
|
|
4442
|
+
if (classDefinitions.has(model))
|
|
4443
|
+
throw new TypeError("Duplicate model class.");
|
|
4444
|
+
const definition = createClassModelDefinition(model);
|
|
4445
|
+
classDefinitions.set(model, definition);
|
|
4446
|
+
implicitRepositories.push(definition.repository);
|
|
4447
|
+
return definition;
|
|
4448
|
+
});
|
|
4449
|
+
repositories = Object.freeze([...repositories, ...implicitRepositories]);
|
|
4426
4450
|
repositoryEffects = definitionArray(repositoryEffects);
|
|
4427
4451
|
const repos = new Set;
|
|
4428
4452
|
const repoNames = new Set;
|
|
@@ -4449,8 +4473,9 @@ function snapshotRegistry(repositories = [], models = [], repositoryEffects = []
|
|
|
4449
4473
|
}
|
|
4450
4474
|
for (const declaration of repositoryEffects) {
|
|
4451
4475
|
assertRepositoryEffectsDeclaration(declaration);
|
|
4452
|
-
|
|
4453
|
-
|
|
4476
|
+
const effectRepository = isModelClass(declaration.definition) ? classDefinitions.get(declaration.definition)?.repository : declaration.definition;
|
|
4477
|
+
assertDefinition(effectRepository, "repository");
|
|
4478
|
+
if (!repos.has(effectRepository))
|
|
4454
4479
|
throw new TypeError("Effect repository is not registered.");
|
|
4455
4480
|
for (const effect of declaration.effects) {
|
|
4456
4481
|
if (effect.transactional)
|
|
@@ -4459,7 +4484,7 @@ function snapshotRegistry(repositories = [], models = [], repositoryEffects = []
|
|
|
4459
4484
|
add(effect.afterCommit);
|
|
4460
4485
|
}
|
|
4461
4486
|
}
|
|
4462
|
-
for (const definition of
|
|
4487
|
+
for (const definition of resolvedModels) {
|
|
4463
4488
|
assertDefinition(definition, "model");
|
|
4464
4489
|
if (definitions.has(definition) || !repos.has(definition.repository))
|
|
4465
4490
|
throw new TypeError("Duplicate model or unregistered repository.");
|
|
@@ -4483,7 +4508,8 @@ function snapshotRegistry(repositories = [], models = [], repositoryEffects = []
|
|
|
4483
4508
|
}
|
|
4484
4509
|
return Object.freeze({
|
|
4485
4510
|
repositories: Object.freeze([...repositories]),
|
|
4486
|
-
models: Object.freeze(
|
|
4511
|
+
models: Object.freeze(resolvedModels),
|
|
4512
|
+
classes: classDefinitions,
|
|
4487
4513
|
dependencies: Object.freeze(dependencies),
|
|
4488
4514
|
repositoryEffects
|
|
4489
4515
|
});
|
|
@@ -4496,7 +4522,7 @@ function prepareRegistry(snapshot, values, app) {
|
|
|
4496
4522
|
const bus = new EventBus;
|
|
4497
4523
|
for (const effect of [
|
|
4498
4524
|
...definition.effects,
|
|
4499
|
-
...snapshot.repositoryEffects.filter((item) => item.definition === definition).flatMap((item) => item.effects)
|
|
4525
|
+
...snapshot.repositoryEffects.filter((item) => (isModelClass(item.definition) ? snapshot.classes.get(item.definition)?.repository : item.definition) === definition).flatMap((item) => item.effects)
|
|
4500
4526
|
]) {
|
|
4501
4527
|
if (effect.transactional) {
|
|
4502
4528
|
const listener = resolve(effect.transactional);
|
|
@@ -4531,7 +4557,7 @@ function prepareRegistry(snapshot, values, app) {
|
|
|
4531
4557
|
for (const name of [definition.name, ...definition.aliases])
|
|
4532
4558
|
names.set(name, definition);
|
|
4533
4559
|
}
|
|
4534
|
-
return Object.freeze({ app, repositories, models, names });
|
|
4560
|
+
return Object.freeze({ app, repositories, models, names, classes: snapshot.classes });
|
|
4535
4561
|
}
|
|
4536
4562
|
function createBoundRegistryFactory(prepared, context, ownership, configuredPool) {
|
|
4537
4563
|
const attachments = new WeakMap;
|
|
@@ -4565,8 +4591,11 @@ function createBoundRegistryFactory(prepared, context, ownership, configuredPool
|
|
|
4565
4591
|
},
|
|
4566
4592
|
model(definition) {
|
|
4567
4593
|
authority.assertActive();
|
|
4568
|
-
|
|
4569
|
-
|
|
4594
|
+
const resolved = typeof definition === "function" ? prepared.classes.get(definition) : definition;
|
|
4595
|
+
if (!resolved)
|
|
4596
|
+
throw new TypeError("Model is not registered in this application.");
|
|
4597
|
+
assertDefinition(resolved, "model");
|
|
4598
|
+
const erased = resolved;
|
|
4570
4599
|
const template = prepared.models.get(erased);
|
|
4571
4600
|
if (!template)
|
|
4572
4601
|
throw new TypeError("Model is not registered in this application.");
|
|
@@ -5446,7 +5475,9 @@ class TransactionRuntime {
|
|
|
5446
5475
|
};
|
|
5447
5476
|
const session = {
|
|
5448
5477
|
repository: (definition) => registry.repository(definition),
|
|
5449
|
-
model
|
|
5478
|
+
get model() {
|
|
5479
|
+
return registry.model;
|
|
5480
|
+
},
|
|
5450
5481
|
dialect: branch.pool.dialect,
|
|
5451
5482
|
capabilities: branch.pool.capabilities,
|
|
5452
5483
|
execute: (input) => {
|
|
@@ -5818,7 +5849,9 @@ function createDatabaseSession(manager, context, operations, ownership, prepared
|
|
|
5818
5849
|
};
|
|
5819
5850
|
const session = {
|
|
5820
5851
|
repository: (definition) => registry.repository(definition),
|
|
5821
|
-
model
|
|
5852
|
+
get model() {
|
|
5853
|
+
return registry.model;
|
|
5854
|
+
},
|
|
5822
5855
|
dialect: pool.dialect,
|
|
5823
5856
|
capabilities: pool.capabilities,
|
|
5824
5857
|
execute: (input) => {
|
|
@@ -11464,17 +11497,24 @@ class QueryFormRequest {
|
|
|
11464
11497
|
}
|
|
11465
11498
|
// ../../src/core/http/index.ts
|
|
11466
11499
|
import {
|
|
11467
|
-
BadRequestError as
|
|
11500
|
+
BadRequestError as BadRequestError6,
|
|
11468
11501
|
ConflictError as ConflictError2,
|
|
11469
11502
|
ForbiddenError as ForbiddenError8,
|
|
11470
11503
|
HttpError,
|
|
11471
11504
|
NotFoundError as NotFoundError3,
|
|
11472
|
-
PayloadTooLargeError as
|
|
11505
|
+
PayloadTooLargeError as PayloadTooLargeError2,
|
|
11473
11506
|
PreconditionFailedError as PreconditionFailedError2,
|
|
11474
11507
|
UnauthorizedError as UnauthorizedError2,
|
|
11475
11508
|
UnprocessableEntityError as UnprocessableEntityError4,
|
|
11476
11509
|
ValidationError as ValidationError2
|
|
11477
11510
|
} from "@getstrata/core/errors/http";
|
|
11511
|
+
import {
|
|
11512
|
+
parseMultipartUpload,
|
|
11513
|
+
parseMultipartUploadStream,
|
|
11514
|
+
sanitizeUploadFileName,
|
|
11515
|
+
UploadedFile,
|
|
11516
|
+
validateUploadFile
|
|
11517
|
+
} from "@getstrata/core/http/parseMultipartUpload";
|
|
11478
11518
|
|
|
11479
11519
|
// ../../src/core/http/authMiddleware.ts
|
|
11480
11520
|
import { validatedAuthOutcome as validatedAuthOutcome2 } from "@getstrata/core/auth/authOutcome";
|
|
@@ -11597,83 +11637,6 @@ function parsePaginationQuery(request) {
|
|
|
11597
11637
|
function paginatedResponse(data, meta, init = {}) {
|
|
11598
11638
|
return Response.json({ data, meta }, init);
|
|
11599
11639
|
}
|
|
11600
|
-
// ../../src/core/http/parseMultipartUpload.ts
|
|
11601
|
-
import { BadRequestError as BadRequestError5, PayloadTooLargeError as PayloadTooLargeError2 } from "@getstrata/core/errors/http";
|
|
11602
|
-
|
|
11603
|
-
// ../../src/core/http/uploads.ts
|
|
11604
|
-
var DEFAULT_MAX_UPLOAD_BYTES = 5 * 1024 * 1024;
|
|
11605
|
-
var ALLOWED_UPLOAD_MIME_TYPES = new Set([
|
|
11606
|
-
"application/pdf",
|
|
11607
|
-
"application/json",
|
|
11608
|
-
"application/zip",
|
|
11609
|
-
"application/x-zip-compressed",
|
|
11610
|
-
"image/jpeg",
|
|
11611
|
-
"image/png",
|
|
11612
|
-
"image/gif",
|
|
11613
|
-
"image/webp",
|
|
11614
|
-
"text/plain",
|
|
11615
|
-
"text/csv"
|
|
11616
|
-
]);
|
|
11617
|
-
var DEFAULT_UPLOAD_POLICY = Object.freeze({
|
|
11618
|
-
maxBytes: DEFAULT_MAX_UPLOAD_BYTES,
|
|
11619
|
-
allowUnknownMime: false
|
|
11620
|
-
});
|
|
11621
|
-
function normalizeMimeType(mimeType) {
|
|
11622
|
-
return mimeType.split(";")[0]?.trim().toLowerCase() ?? "";
|
|
11623
|
-
}
|
|
11624
|
-
function isAllowedMimeType(mimeType, allowUnknownMime = false) {
|
|
11625
|
-
const normalized = normalizeMimeType(mimeType);
|
|
11626
|
-
if (!normalized || normalized === "application/octet-stream") {
|
|
11627
|
-
return allowUnknownMime;
|
|
11628
|
-
}
|
|
11629
|
-
return ALLOWED_UPLOAD_MIME_TYPES.has(normalized);
|
|
11630
|
-
}
|
|
11631
|
-
|
|
11632
|
-
// ../../src/core/http/parseMultipartUpload.ts
|
|
11633
|
-
function normalizeMimeType2(mimeType) {
|
|
11634
|
-
return mimeType.split(";")[0]?.trim().toLowerCase() || "application/octet-stream";
|
|
11635
|
-
}
|
|
11636
|
-
function sanitizeUploadFileName(name) {
|
|
11637
|
-
const base = name.split(/[/\\]/).pop()?.trim() ?? "upload";
|
|
11638
|
-
const sanitized = base.replace(/[^\w.\-()+ ]+/g, "_").slice(0, 200);
|
|
11639
|
-
return sanitized.length > 0 ? sanitized : "upload";
|
|
11640
|
-
}
|
|
11641
|
-
async function validateUploadFile(file, fieldName = "file", policy = DEFAULT_UPLOAD_POLICY) {
|
|
11642
|
-
if (!Number.isSafeInteger(policy.maxBytes) || policy.maxBytes <= 0)
|
|
11643
|
-
throw new RangeError("Upload limit must be a positive safe integer.");
|
|
11644
|
-
if (!(file instanceof File)) {
|
|
11645
|
-
throw new BadRequestError5(`Missing upload field "${fieldName}".`);
|
|
11646
|
-
}
|
|
11647
|
-
if (file.size <= 0) {
|
|
11648
|
-
throw new BadRequestError5("Uploaded file is empty.");
|
|
11649
|
-
}
|
|
11650
|
-
const maxBytes = policy.maxBytes;
|
|
11651
|
-
if (file.size > maxBytes) {
|
|
11652
|
-
throw new PayloadTooLargeError2(`Upload exceeds the ${maxBytes} byte limit.`);
|
|
11653
|
-
}
|
|
11654
|
-
const mimeType = normalizeMimeType2(file.type.trim() || "application/octet-stream");
|
|
11655
|
-
if (!isAllowedMimeType(mimeType, policy.allowUnknownMime)) {
|
|
11656
|
-
throw new BadRequestError5(`File type "${mimeType}" is not allowed.`);
|
|
11657
|
-
}
|
|
11658
|
-
return {
|
|
11659
|
-
fileName: sanitizeUploadFileName(file.name),
|
|
11660
|
-
mimeType,
|
|
11661
|
-
size: file.size,
|
|
11662
|
-
contents: new Uint8Array(await file.arrayBuffer())
|
|
11663
|
-
};
|
|
11664
|
-
}
|
|
11665
|
-
async function parseMultipartUpload(request, fieldName = "file", policy = DEFAULT_UPLOAD_POLICY) {
|
|
11666
|
-
const contentType = request.headers.get("content-type")?.toLowerCase() ?? "";
|
|
11667
|
-
if (!contentType.includes("multipart/form-data")) {
|
|
11668
|
-
throw new BadRequestError5("Expected multipart form data.");
|
|
11669
|
-
}
|
|
11670
|
-
const formData = await request.formData();
|
|
11671
|
-
const value = formData.get(fieldName);
|
|
11672
|
-
if (!(value instanceof File)) {
|
|
11673
|
-
throw new BadRequestError5(`Missing upload field "${fieldName}".`);
|
|
11674
|
-
}
|
|
11675
|
-
return validateUploadFile(value, fieldName, policy);
|
|
11676
|
-
}
|
|
11677
11640
|
// ../../src/core/http/requireAuthMiddleware.ts
|
|
11678
11641
|
import { UnauthorizedError } from "@getstrata/core/errors/http";
|
|
11679
11642
|
function createRequireAuthMiddleware(auth) {
|
|
@@ -11824,7 +11787,7 @@ function bindRouteModel(param, resolver, handler) {
|
|
|
11824
11787
|
};
|
|
11825
11788
|
}
|
|
11826
11789
|
// ../../src/core/http/securedRouteModelBinding.ts
|
|
11827
|
-
import { BadRequestError as
|
|
11790
|
+
import { BadRequestError as BadRequestError5, NotFoundError as NotFoundError2 } from "@getstrata/core/errors/http";
|
|
11828
11791
|
function snapshotPorts(ports) {
|
|
11829
11792
|
const auth = ports?.auth, resolve = auth?.resolve, authorize = ports?.authorize, etagEnabled = ports?.etagEnabled;
|
|
11830
11793
|
if (typeof resolve !== "function" || typeof authorize !== "function" || typeof etagEnabled !== "boolean")
|
|
@@ -11888,7 +11851,7 @@ function securedBindRouteModelByKey(param, resolver, authorization, handler, por
|
|
|
11888
11851
|
return async (request) => {
|
|
11889
11852
|
const key = String(request.params[param] ?? "").trim();
|
|
11890
11853
|
if (!key) {
|
|
11891
|
-
throw new
|
|
11854
|
+
throw new BadRequestError5(`Missing route parameter "${String(param)}".`);
|
|
11892
11855
|
}
|
|
11893
11856
|
const model = requireResolvedModel(await resolver(key, request));
|
|
11894
11857
|
const user = await selected.auth.resolve(request);
|
|
@@ -12706,11 +12669,11 @@ function createValidateSignatureMiddleware(options) {
|
|
|
12706
12669
|
};
|
|
12707
12670
|
}
|
|
12708
12671
|
// ../../src/core/http/parseFormBody.ts
|
|
12709
|
-
import { BadRequestError as
|
|
12672
|
+
import { BadRequestError as BadRequestError7 } from "@getstrata/core/errors/http";
|
|
12710
12673
|
async function parseFormBody(request, options = {}) {
|
|
12711
12674
|
const contentType = request.headers.get("content-type")?.toLowerCase() ?? "";
|
|
12712
12675
|
if (!contentType.includes("application/x-www-form-urlencoded") && !contentType.includes("multipart/form-data")) {
|
|
12713
|
-
throw new
|
|
12676
|
+
throw new BadRequestError7("Expected a form submission.");
|
|
12714
12677
|
}
|
|
12715
12678
|
return formDataToRecord(await request.formData(), options);
|
|
12716
12679
|
}
|
|
@@ -16719,7 +16682,7 @@ export {
|
|
|
16719
16682
|
AuthAccountNotFoundError,
|
|
16720
16683
|
AuthManager,
|
|
16721
16684
|
AuthenticationRequiredError2 as AuthenticationRequiredError,
|
|
16722
|
-
|
|
16685
|
+
BadRequestError8 as BadRequestError,
|
|
16723
16686
|
BaseRepository4 as BaseRepository,
|
|
16724
16687
|
BasicAuthGuard,
|
|
16725
16688
|
BelongsToManyRelationQuery,
|
|
@@ -16783,7 +16746,7 @@ export {
|
|
|
16783
16746
|
Notification,
|
|
16784
16747
|
NotificationDispatcher,
|
|
16785
16748
|
OidcProvider,
|
|
16786
|
-
|
|
16749
|
+
PayloadTooLargeError3 as PayloadTooLargeError,
|
|
16787
16750
|
PersistenceError6 as PersistenceError,
|
|
16788
16751
|
Policy,
|
|
16789
16752
|
PolicyDeniedError,
|
|
@@ -16816,6 +16779,7 @@ export {
|
|
|
16816
16779
|
UnauthorizedError4 as UnauthorizedError,
|
|
16817
16780
|
UnprocessableEntityError5 as UnprocessableEntityError,
|
|
16818
16781
|
UnsupportedSchemaFeatureError,
|
|
16782
|
+
UploadedFile2 as UploadedFile,
|
|
16819
16783
|
ValidationError4 as ValidationError,
|
|
16820
16784
|
ViewRenderer,
|
|
16821
16785
|
WebFormRequest,
|
|
@@ -16966,6 +16930,7 @@ export {
|
|
|
16966
16930
|
etagFromResource,
|
|
16967
16931
|
etagValuesMatch,
|
|
16968
16932
|
expectObject,
|
|
16933
|
+
field,
|
|
16969
16934
|
fieldEncryptionRotationRepository,
|
|
16970
16935
|
filterMassAssignable,
|
|
16971
16936
|
foreignKeyFromTable,
|
|
@@ -17029,7 +16994,9 @@ export {
|
|
|
17029
16994
|
mergeRouteMaps,
|
|
17030
16995
|
migrateDatabase,
|
|
17031
16996
|
minLength,
|
|
16997
|
+
modelEffects,
|
|
17032
16998
|
modelEventName,
|
|
16999
|
+
modelTable,
|
|
17033
17000
|
morphMany,
|
|
17034
17001
|
morphOne,
|
|
17035
17002
|
morphTo,
|
|
@@ -17043,7 +17010,8 @@ export {
|
|
|
17043
17010
|
paginatedResponse,
|
|
17044
17011
|
parseApplicationConfig,
|
|
17045
17012
|
parseJsonBody,
|
|
17046
|
-
parseMultipartUpload,
|
|
17013
|
+
parseMultipartUpload2 as parseMultipartUpload,
|
|
17014
|
+
parseMultipartUploadStream2 as parseMultipartUploadStream,
|
|
17047
17015
|
parseOptionalBooleanQueryParam,
|
|
17048
17016
|
parseOptionalEnumQueryParam,
|
|
17049
17017
|
parseOptionalPositiveIntQueryParam,
|
|
@@ -17125,7 +17093,7 @@ export {
|
|
|
17125
17093
|
safeInternalRedirectPath,
|
|
17126
17094
|
sanitizeInternalPath,
|
|
17127
17095
|
sanitizeMailHtml,
|
|
17128
|
-
sanitizeUploadFileName,
|
|
17096
|
+
sanitizeUploadFileName2 as sanitizeUploadFileName,
|
|
17129
17097
|
scopedOrganizationIds,
|
|
17130
17098
|
sdkClientClassName,
|
|
17131
17099
|
securedBindRouteModel,
|
|
@@ -17158,7 +17126,7 @@ export {
|
|
|
17158
17126
|
trustForwardedFor,
|
|
17159
17127
|
uniqueColumnSelect,
|
|
17160
17128
|
validateObject,
|
|
17161
|
-
validateUploadFile,
|
|
17129
|
+
validateUploadFile2 as validateUploadFile,
|
|
17162
17130
|
validatedAuthOutcome,
|
|
17163
17131
|
valueService,
|
|
17164
17132
|
verifyCsrfToken,
|
|
@@ -2514,7 +2514,10 @@ class BaseRepository {
|
|
|
2514
2514
|
var baseRepository_default = BaseRepository;
|
|
2515
2515
|
// ../../src/core/database/model.ts
|
|
2516
2516
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
|
|
2517
|
-
import {
|
|
2517
|
+
import {
|
|
2518
|
+
defineModel as defineModelDefinition,
|
|
2519
|
+
defineRepository as defineRepository2
|
|
2520
|
+
} from "@getstrata/core/database/definitions";
|
|
2518
2521
|
import { isUniqueConstraintError, RecordNotFoundError as RecordNotFoundError2 } from "@getstrata/core/database/errors";
|
|
2519
2522
|
import { getBindingPorts as getBindingPorts5 } from "#strata-orm-internal";
|
|
2520
2523
|
|
|
@@ -2687,6 +2690,156 @@ function applyTimestampsOnUpdate(columns, values, enabled) {
|
|
|
2687
2690
|
return result;
|
|
2688
2691
|
}
|
|
2689
2692
|
|
|
2693
|
+
// ../../src/core/database/modelAuthoring.ts
|
|
2694
|
+
import {
|
|
2695
|
+
defineModel as defineDefinition,
|
|
2696
|
+
defineRepository
|
|
2697
|
+
} from "@getstrata/core/database/definitions";
|
|
2698
|
+
import { BaseRepository as BaseRepository2, Model } from "#strata-orm-runtime";
|
|
2699
|
+
var fieldBrand = Symbol("database.model.field");
|
|
2700
|
+
function modelField(cast) {
|
|
2701
|
+
return Object.freeze({
|
|
2702
|
+
[fieldBrand]: undefined,
|
|
2703
|
+
...cast ? { cast } : {},
|
|
2704
|
+
nullable: () => modelField(cast)
|
|
2705
|
+
});
|
|
2706
|
+
}
|
|
2707
|
+
var field = Object.freeze({
|
|
2708
|
+
string: () => modelField(),
|
|
2709
|
+
number: () => modelField(),
|
|
2710
|
+
boolean: () => modelField(),
|
|
2711
|
+
nullable: (value) => value.nullable(),
|
|
2712
|
+
timestamp: () => modelField(),
|
|
2713
|
+
date: () => modelField(),
|
|
2714
|
+
json: () => modelField("json"),
|
|
2715
|
+
binary: () => modelField()
|
|
2716
|
+
});
|
|
2717
|
+
var declarations = new WeakMap;
|
|
2718
|
+
function ownRecord(input) {
|
|
2719
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
2720
|
+
throw new TypeError("Model metadata must be a plain record.");
|
|
2721
|
+
const prototype = Object.getPrototypeOf(input);
|
|
2722
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
2723
|
+
throw new TypeError("Model metadata must be a plain record.");
|
|
2724
|
+
const result = Object.create(null);
|
|
2725
|
+
for (const key of Reflect.ownKeys(input)) {
|
|
2726
|
+
const descriptor = Object.getOwnPropertyDescriptor(input, key);
|
|
2727
|
+
if (typeof key !== "string" || !descriptor || !("value" in descriptor))
|
|
2728
|
+
throw new TypeError("Model metadata accessors are unsupported.");
|
|
2729
|
+
result[key] = descriptor.value;
|
|
2730
|
+
}
|
|
2731
|
+
return result;
|
|
2732
|
+
}
|
|
2733
|
+
function defineAuthoredModel(options) {
|
|
2734
|
+
const values = ownRecord(options);
|
|
2735
|
+
if (Object.keys(values).some((key) => !["table", "fields", "primaryKey", "name", "defaultOrderBy", "softDeletes"].includes(key)))
|
|
2736
|
+
throw new TypeError("Unknown class model option.");
|
|
2737
|
+
if (typeof values.table !== "string" || !values.table.trim())
|
|
2738
|
+
throw new TypeError("Model table must be a nonempty string.");
|
|
2739
|
+
const fields = ownRecord(values.fields);
|
|
2740
|
+
const columns = Object.keys(fields);
|
|
2741
|
+
const casts = Object.create(null);
|
|
2742
|
+
for (const [name, value] of Object.entries(fields)) {
|
|
2743
|
+
if (!name || !value || typeof value !== "object" || !Object.isFrozen(value) || !Object.hasOwn(value, fieldBrand))
|
|
2744
|
+
throw new TypeError("Expected a typed model field.");
|
|
2745
|
+
const cast = value.cast;
|
|
2746
|
+
if (cast)
|
|
2747
|
+
casts[name] = cast;
|
|
2748
|
+
}
|
|
2749
|
+
const primaryKey = values.primaryKey ?? "id";
|
|
2750
|
+
if (typeof primaryKey !== "string" || !columns.includes(primaryKey))
|
|
2751
|
+
throw new TypeError("Model primary key must be a declared field.");
|
|
2752
|
+
const repository = defineRepository({
|
|
2753
|
+
name: `${values.table}.declaration`,
|
|
2754
|
+
table: {
|
|
2755
|
+
name: values.table,
|
|
2756
|
+
primaryKey,
|
|
2757
|
+
columns,
|
|
2758
|
+
defaultOrderBy: values.defaultOrderBy,
|
|
2759
|
+
softDeletes: values.softDeletes
|
|
2760
|
+
},
|
|
2761
|
+
dependencies: [],
|
|
2762
|
+
create: (binding) => new BaseRepository2(binding)
|
|
2763
|
+
});
|
|
2764
|
+
if (values.name !== undefined && (typeof values.name !== "string" || !values.name.trim()))
|
|
2765
|
+
throw new TypeError("Model name must be a nonempty string.");
|
|
2766
|
+
|
|
2767
|
+
class AuthoredModel extends Model {
|
|
2768
|
+
}
|
|
2769
|
+
declarations.set(AuthoredModel, Object.freeze({
|
|
2770
|
+
table: repository.table,
|
|
2771
|
+
...values.name === undefined ? {} : { name: values.name },
|
|
2772
|
+
casts: Object.freeze(casts)
|
|
2773
|
+
}));
|
|
2774
|
+
return AuthoredModel;
|
|
2775
|
+
}
|
|
2776
|
+
function declarationFor(value) {
|
|
2777
|
+
if (typeof value !== "function")
|
|
2778
|
+
return;
|
|
2779
|
+
for (let current = value;typeof current === "function"; current = Object.getPrototypeOf(current)) {
|
|
2780
|
+
const declaration = declarations.get(current);
|
|
2781
|
+
if (declaration)
|
|
2782
|
+
return declaration;
|
|
2783
|
+
}
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2786
|
+
function isModelClass(value) {
|
|
2787
|
+
return declarationFor(value) !== undefined;
|
|
2788
|
+
}
|
|
2789
|
+
function staticValue(model, key) {
|
|
2790
|
+
for (let current = model;typeof current === "function"; current = Object.getPrototypeOf(current)) {
|
|
2791
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
2792
|
+
if (descriptor) {
|
|
2793
|
+
if (!("value" in descriptor))
|
|
2794
|
+
throw new TypeError("Model metadata accessors are unsupported.");
|
|
2795
|
+
return descriptor.value;
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
return;
|
|
2799
|
+
}
|
|
2800
|
+
function createClassModelDefinition(model) {
|
|
2801
|
+
const declaration = declarationFor(model);
|
|
2802
|
+
if (!declaration)
|
|
2803
|
+
throw new TypeError("Expected an authored model class.");
|
|
2804
|
+
const name = declaration.name ?? staticValue(model, "name");
|
|
2805
|
+
const repository = defineRepository({
|
|
2806
|
+
name: `${name}.repository`,
|
|
2807
|
+
table: declaration.table,
|
|
2808
|
+
dependencies: [],
|
|
2809
|
+
create: (binding) => new BaseRepository2(binding)
|
|
2810
|
+
});
|
|
2811
|
+
const attributes = { timestamps: true, casts: declaration.casts };
|
|
2812
|
+
for (const key of [
|
|
2813
|
+
"fillable",
|
|
2814
|
+
"guarded",
|
|
2815
|
+
"casts",
|
|
2816
|
+
"timestamps",
|
|
2817
|
+
"hidden",
|
|
2818
|
+
"visible",
|
|
2819
|
+
"appends"
|
|
2820
|
+
]) {
|
|
2821
|
+
const value = staticValue(model, `$${key}`);
|
|
2822
|
+
if (value !== undefined)
|
|
2823
|
+
attributes[key] = key === "casts" ? { ...declaration.casts, ...ownRecord(value) } : value;
|
|
2824
|
+
}
|
|
2825
|
+
const Class = model;
|
|
2826
|
+
return defineDefinition({
|
|
2827
|
+
name,
|
|
2828
|
+
repository,
|
|
2829
|
+
dependencies: [],
|
|
2830
|
+
attributes,
|
|
2831
|
+
aliases: staticValue(model, "$aliases"),
|
|
2832
|
+
observers: staticValue(model, "$observers"),
|
|
2833
|
+
construct: (state, binding) => new Class(state, binding)
|
|
2834
|
+
});
|
|
2835
|
+
}
|
|
2836
|
+
function modelTable(model) {
|
|
2837
|
+
const declaration = declarationFor(model);
|
|
2838
|
+
if (!declaration)
|
|
2839
|
+
throw new TypeError("Expected an authored model class.");
|
|
2840
|
+
return declaration.table;
|
|
2841
|
+
}
|
|
2842
|
+
|
|
2690
2843
|
// ../../src/core/database/modelQuery.ts
|
|
2691
2844
|
import { RecordNotFoundError } from "@getstrata/core/database/errors";
|
|
2692
2845
|
import { getBindingPorts as getBindingPorts3 } from "#strata-orm-internal";
|
|
@@ -3310,7 +3463,7 @@ class HasManyRelationQuery {
|
|
|
3310
3463
|
const binding = getRepositoryBinding(this.parent.getRepository());
|
|
3311
3464
|
try {
|
|
3312
3465
|
plan = this.snapshot();
|
|
3313
|
-
if (related instanceof
|
|
3466
|
+
if (related instanceof Model2) {
|
|
3314
3467
|
const source = getModelBinding(related);
|
|
3315
3468
|
if (source.session !== binding.session)
|
|
3316
3469
|
throw new TypeError("Related model requires the exact active session.");
|
|
@@ -4163,7 +4316,7 @@ class HasManyThroughRelationQuery {
|
|
|
4163
4316
|
}
|
|
4164
4317
|
|
|
4165
4318
|
// ../../src/core/database/model.ts
|
|
4166
|
-
import {
|
|
4319
|
+
import { modelEffects } from "@getstrata/core/database/definitions";
|
|
4167
4320
|
function accessorName(key) {
|
|
4168
4321
|
const pascal = key.replace(/_([a-z])/g, (_match, letter) => letter.toUpperCase());
|
|
4169
4322
|
return `get${pascal.charAt(0).toUpperCase()}${pascal.slice(1)}Attribute`;
|
|
@@ -4220,7 +4373,7 @@ async function runObservers(entity, event) {
|
|
|
4220
4373
|
return true;
|
|
4221
4374
|
}
|
|
4222
4375
|
|
|
4223
|
-
class
|
|
4376
|
+
class Model2 {
|
|
4224
4377
|
#attributes;
|
|
4225
4378
|
#originalAttributes;
|
|
4226
4379
|
#exists;
|
|
@@ -4609,7 +4762,7 @@ class Model {
|
|
|
4609
4762
|
}
|
|
4610
4763
|
const resolvedMap = Object.fromEntries(Object.entries(relatedByType).map(([type, related]) => [
|
|
4611
4764
|
type,
|
|
4612
|
-
getBindingPorts5(this.#binding).model(typeof related === "function" ? related() : related)
|
|
4765
|
+
getBindingPorts5(this.#binding).model(typeof related === "function" && !(related.prototype instanceof Model2) ? related() : related)
|
|
4613
4766
|
]));
|
|
4614
4767
|
return new MorphToRelationQuery(this, resolvedMap, morphTo({
|
|
4615
4768
|
name: resolvedName,
|
|
@@ -4774,7 +4927,7 @@ class BoundModelFacade {
|
|
|
4774
4927
|
return target.construct(inspectModelState(source), source);
|
|
4775
4928
|
}
|
|
4776
4929
|
resolveRelated(reference) {
|
|
4777
|
-
const definition = typeof reference === "function" ? reference() : reference;
|
|
4930
|
+
const definition = typeof reference === "function" && !(reference.prototype instanceof Model2) ? reference() : reference;
|
|
4778
4931
|
return getBindingPorts5(this.binding).model(definition);
|
|
4779
4932
|
}
|
|
4780
4933
|
terminal(work, input) {
|
|
@@ -4982,6 +5135,11 @@ class BoundModelFacade {
|
|
|
4982
5135
|
function createBoundModel(binding) {
|
|
4983
5136
|
return new BoundModelFacade(binding);
|
|
4984
5137
|
}
|
|
5138
|
+
var defineModel = (options) => {
|
|
5139
|
+
if (Object.getOwnPropertyDescriptor(options, "fields"))
|
|
5140
|
+
return defineAuthoredModel(options);
|
|
5141
|
+
return defineModelDefinition(options);
|
|
5142
|
+
};
|
|
4985
5143
|
function createModel(options) {
|
|
4986
5144
|
const prototype = Object.getPrototypeOf(options);
|
|
4987
5145
|
if (prototype !== Object.prototype && prototype !== null)
|
|
@@ -4993,7 +5151,7 @@ function createModel(options) {
|
|
|
4993
5151
|
}
|
|
4994
5152
|
if (typeof options.name !== "string" || !options.name.trim())
|
|
4995
5153
|
throw new TypeError("Model names must be nonempty strings.");
|
|
4996
|
-
const repository =
|
|
5154
|
+
const repository = defineRepository2({
|
|
4997
5155
|
name: `${options.name}.repository`,
|
|
4998
5156
|
table: options.table,
|
|
4999
5157
|
dependencies: [],
|
|
@@ -5010,7 +5168,7 @@ function createModel(options) {
|
|
|
5010
5168
|
timestamps: { value: false, enumerable: true, configurable: true },
|
|
5011
5169
|
...Object.getOwnPropertyDescriptors(options.attributes)
|
|
5012
5170
|
}),
|
|
5013
|
-
construct: (state, binding) => new
|
|
5171
|
+
construct: (state, binding) => new Model2(state, binding)
|
|
5014
5172
|
});
|
|
5015
5173
|
}
|
|
5016
5174
|
export {
|
|
@@ -5021,17 +5179,23 @@ export {
|
|
|
5021
5179
|
HasManyRelationQuery,
|
|
5022
5180
|
HasManyThroughRelationQuery,
|
|
5023
5181
|
HasOneRelationQuery,
|
|
5024
|
-
Model,
|
|
5182
|
+
Model2 as Model,
|
|
5025
5183
|
ModelQuery,
|
|
5026
5184
|
MorphManyRelationQuery,
|
|
5027
5185
|
MorphOneRelationQuery,
|
|
5028
5186
|
MorphToRelationQuery,
|
|
5029
5187
|
RepositoryQuery,
|
|
5030
5188
|
createBoundModel,
|
|
5189
|
+
createClassModelDefinition,
|
|
5031
5190
|
createModel,
|
|
5191
|
+
defineAuthoredModel,
|
|
5192
|
+
defineModel,
|
|
5193
|
+
field,
|
|
5032
5194
|
getModelBinding,
|
|
5033
5195
|
getRepositoryBinding,
|
|
5196
|
+
isModelClass,
|
|
5034
5197
|
modelFacade,
|
|
5198
|
+
modelTable,
|
|
5035
5199
|
runObservers,
|
|
5036
5200
|
snapshotRepositoryQuery
|
|
5037
5201
|
};
|