@nhtio/lucid-resourceful 0.1.0-master-75d846ce → 0.1.0-master-e5b91a85
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/{index-ttZHSUea.cjs → index-BZfalkrg.cjs} +102 -10
- package/index-BZfalkrg.cjs.map +1 -0
- package/{index-uZZRhJu0.js → index-D7LFVuTK.js} +102 -10
- package/index-D7LFVuTK.js.map +1 -0
- package/index.cjs +1 -1
- package/index.mjs +1 -1
- package/integration/provider.cjs +1 -1
- package/integration/provider.mjs +1 -1
- package/package.json +28 -28
- package/router/utils.cjs +1 -1
- package/router/utils.mjs +1 -1
- package/router.cjs +1 -1
- package/router.mjs +1 -1
- package/index-ttZHSUea.cjs.map +0 -1
- package/index-uZZRhJu0.js.map +0 -1
|
@@ -4560,6 +4560,21 @@ const getFieldKey = (key, definition) => {
|
|
|
4560
4560
|
};
|
|
4561
4561
|
const filterablePropertiesForModelCache = /* @__PURE__ */ new WeakMap();
|
|
4562
4562
|
const filterableLocalPropertiesForModelCache = /* @__PURE__ */ new Map();
|
|
4563
|
+
const sortableLocalPropertiesForModelCache = /* @__PURE__ */ new WeakMap();
|
|
4564
|
+
const getSortableLocalPropertiesFromModel = (model) => {
|
|
4565
|
+
const cached = sortableLocalPropertiesForModelCache.get(model);
|
|
4566
|
+
if (cached) return cached;
|
|
4567
|
+
const sortable = /* @__PURE__ */ new Set();
|
|
4568
|
+
model.$resourcefulColumns.forEach((definition, key) => {
|
|
4569
|
+
const lucidOptions = model.$getColumn(key);
|
|
4570
|
+
if (definition.sortable && lucidOptions && lucidOptions.serializeAs !== null) {
|
|
4571
|
+
const field = getFieldKey(key, lucidOptions);
|
|
4572
|
+
if (field) sortable.add(field);
|
|
4573
|
+
}
|
|
4574
|
+
});
|
|
4575
|
+
sortableLocalPropertiesForModelCache.set(model, sortable);
|
|
4576
|
+
return sortable;
|
|
4577
|
+
};
|
|
4563
4578
|
const getFilterableLocalPropertiesFromModel = (model) => {
|
|
4564
4579
|
const cached = filterableLocalPropertiesForModelCache.get(model);
|
|
4565
4580
|
if (cached) {
|
|
@@ -6259,9 +6274,10 @@ function withResourceful(options = {}) {
|
|
|
6259
6274
|
});
|
|
6260
6275
|
recordsQuery.select(privateKeyColumn).forPage(validatedMethodOptions.page, validatedMethodOptions.perPage);
|
|
6261
6276
|
if (Array.isArray(sort) && sort.length > 0) {
|
|
6277
|
+
const sortableFields = getSortableLocalPropertiesFromModel(this);
|
|
6262
6278
|
sort.forEach(([field, direction]) => {
|
|
6263
6279
|
const columnName = this.$keys.serializedToColumns.get(field);
|
|
6264
|
-
if (allowedSerializedMap.has(field) && columnName) {
|
|
6280
|
+
if (allowedSerializedMap.has(field) && sortableFields.has(field) && columnName) {
|
|
6265
6281
|
recordsQuery.orderBy(columnName, direction);
|
|
6266
6282
|
}
|
|
6267
6283
|
});
|
|
@@ -15364,6 +15380,8 @@ class ODataToLucidTranslator {
|
|
|
15364
15380
|
}
|
|
15365
15381
|
// (date/math helper mappings removed in favor of dialect-aware #getSqlFns())
|
|
15366
15382
|
}
|
|
15383
|
+
const MIN_DOTNET_DATETIME = luxon.DateTime.utc(1, 1, 1);
|
|
15384
|
+
const MAX_DOTNET_DATETIME = luxon.DateTime.utc(9999, 12, 31, 23, 59, 59, 999);
|
|
15367
15385
|
const encoder = (_key, value) => {
|
|
15368
15386
|
if (value instanceof Date) {
|
|
15369
15387
|
return luxon.DateTime.fromJSDate(value).toISO();
|
|
@@ -15507,12 +15525,6 @@ const coerceEntityForIeee754 = (entity, model, ieee754Compatible, metaCache, vis
|
|
|
15507
15525
|
if (serializeAs === null) continue;
|
|
15508
15526
|
const jsonKey = serializeAs || propertyKey;
|
|
15509
15527
|
if (!(jsonKey in entity)) continue;
|
|
15510
|
-
if (type_guardsDMqlMT2e.isInstanceOf(prop.definition.type, "ResourcefulDateType", definitions.ResourcefulDateType)) {
|
|
15511
|
-
const date = entity[jsonKey];
|
|
15512
|
-
if (date instanceof luxon.DateTime) entity[jsonKey] = date.toISODate();
|
|
15513
|
-
else if (date instanceof Date) entity[jsonKey] = luxon.DateTime.fromJSDate(date).toISODate();
|
|
15514
|
-
continue;
|
|
15515
|
-
}
|
|
15516
15528
|
if (!isIeee754CompatibleRelevantType(prop.definition.type)) continue;
|
|
15517
15529
|
coerceNumericField(entity, jsonKey, ieee754Compatible);
|
|
15518
15530
|
continue;
|
|
@@ -15553,6 +15565,75 @@ const coerceEntityForIeee754 = (entity, model, ieee754Compatible, metaCache, vis
|
|
|
15553
15565
|
}
|
|
15554
15566
|
}
|
|
15555
15567
|
};
|
|
15568
|
+
const toLuxonDateTime = (raw) => {
|
|
15569
|
+
if (raw instanceof luxon.DateTime) return raw;
|
|
15570
|
+
if (raw instanceof Date) return luxon.DateTime.fromJSDate(raw);
|
|
15571
|
+
if (typeof raw === "string") return luxon.DateTime.fromISO(raw, { setZone: true });
|
|
15572
|
+
if (raw && typeof raw === "object" && raw.isLuxonDateTime === true && typeof raw.toISO === "function") {
|
|
15573
|
+
const iso = raw.toISO();
|
|
15574
|
+
return iso ? luxon.DateTime.fromISO(iso, { setZone: true }) : void 0;
|
|
15575
|
+
}
|
|
15576
|
+
return void 0;
|
|
15577
|
+
};
|
|
15578
|
+
const coerceDateValueToRange = (raw, kind, nullable) => {
|
|
15579
|
+
const date = toLuxonDateTime(raw);
|
|
15580
|
+
if (!date?.isValid) return void 0;
|
|
15581
|
+
if (kind === "date") {
|
|
15582
|
+
if (date.year < 1 || date.year > 9999) {
|
|
15583
|
+
return nullable ? null : date.year < 1 ? "0001-01-01" : "9999-12-31";
|
|
15584
|
+
}
|
|
15585
|
+
return typeof raw === "string" ? void 0 : date.toISODate();
|
|
15586
|
+
}
|
|
15587
|
+
const millis = date.toUTC().toMillis();
|
|
15588
|
+
const below = date.year < 1 || millis < MIN_DOTNET_DATETIME.toMillis();
|
|
15589
|
+
if (below || date.year > 9999 || millis > MAX_DOTNET_DATETIME.toMillis()) {
|
|
15590
|
+
return nullable ? null : below ? MIN_DOTNET_DATETIME.toISO() : MAX_DOTNET_DATETIME.toISO();
|
|
15591
|
+
}
|
|
15592
|
+
return void 0;
|
|
15593
|
+
};
|
|
15594
|
+
const coerceEntityDateRange = (entity, model, metaCache, visited = /* @__PURE__ */ new WeakSet()) => {
|
|
15595
|
+
if (visited.has(entity)) return;
|
|
15596
|
+
visited.add(entity);
|
|
15597
|
+
const meta = metaCache.get(model);
|
|
15598
|
+
if (!meta) return;
|
|
15599
|
+
for (const [propertyKey, prop] of Object.entries(meta.properties)) {
|
|
15600
|
+
if (prop.kind === "column" || prop.kind === "computedAccessor") {
|
|
15601
|
+
const serializeAs = prop.lucidDefinitions?.serializeAs;
|
|
15602
|
+
if (serializeAs === null) continue;
|
|
15603
|
+
const key = serializeAs || propertyKey;
|
|
15604
|
+
if (!(key in entity)) continue;
|
|
15605
|
+
const dateType = type_guardsDMqlMT2e.isInstanceOf(
|
|
15606
|
+
prop.definition.type,
|
|
15607
|
+
"ResourcefulDateType",
|
|
15608
|
+
definitions.ResourcefulDateType
|
|
15609
|
+
);
|
|
15610
|
+
if (!dateType && !type_guardsDMqlMT2e.isInstanceOf(prop.definition.type, "ResourcefulDateTimeType", definitions.ResourcefulDateTimeType))
|
|
15611
|
+
continue;
|
|
15612
|
+
const coerced = coerceDateValueToRange(
|
|
15613
|
+
entity[key],
|
|
15614
|
+
dateType ? "date" : "dateTime",
|
|
15615
|
+
prop.definition.nullable
|
|
15616
|
+
);
|
|
15617
|
+
if (coerced !== void 0) entity[key] = coerced;
|
|
15618
|
+
continue;
|
|
15619
|
+
}
|
|
15620
|
+
if (prop.kind !== "relationship" || !(propertyKey in entity)) continue;
|
|
15621
|
+
const nested = entity[propertyKey];
|
|
15622
|
+
if (!nested || typeof nested !== "object") continue;
|
|
15623
|
+
let related = null;
|
|
15624
|
+
try {
|
|
15625
|
+
const candidate = prop.relatedModel();
|
|
15626
|
+
if (decorator_utils.isResourcefulModel(candidate)) related = candidate;
|
|
15627
|
+
} catch {
|
|
15628
|
+
}
|
|
15629
|
+
if (!related) continue;
|
|
15630
|
+
if (Array.isArray(nested)) {
|
|
15631
|
+
for (const item of nested)
|
|
15632
|
+
if (item && typeof item === "object")
|
|
15633
|
+
coerceEntityDateRange(item, related, metaCache, visited);
|
|
15634
|
+
} else coerceEntityDateRange(nested, related, metaCache, visited);
|
|
15635
|
+
}
|
|
15636
|
+
};
|
|
15556
15637
|
const modelRelationshipSyncPayloadSchema = joi.joi.object({
|
|
15557
15638
|
ruids: joi.joi.array().items(joi.joi.alternatives().try(joi.joi.string().required(), joi.joi.number().integer().required())).required()
|
|
15558
15639
|
});
|
|
@@ -15846,6 +15927,7 @@ class ResourcefulModelController2 {
|
|
|
15846
15927
|
const applyIeee754Coercion = (jsonEntity) => {
|
|
15847
15928
|
if (!coercionModel) return;
|
|
15848
15929
|
if (!jsonEntity || typeof jsonEntity !== "object" || Array.isArray(jsonEntity)) return;
|
|
15930
|
+
coerceEntityDateRange(jsonEntity, coercionModel, metaCache);
|
|
15849
15931
|
coerceEntityForIeee754(
|
|
15850
15932
|
jsonEntity,
|
|
15851
15933
|
coercionModel,
|
|
@@ -15905,6 +15987,9 @@ class ResourcefulModelController2 {
|
|
|
15905
15987
|
const dNs = "http://docs.oasis-open.org/odata/ns/data";
|
|
15906
15988
|
const buildEntry = (entity, meta) => {
|
|
15907
15989
|
const obj = coercionModel ? serializeResourcefulDates(toJsonEntity(entity), coercionModel) : toJsonEntity(entity);
|
|
15990
|
+
if (coercionModel && type_guardsDMqlMT2e.isObject$1(obj)) {
|
|
15991
|
+
coerceEntityDateRange(obj, coercionModel, metaCache);
|
|
15992
|
+
}
|
|
15908
15993
|
const entryAttrs = errors$1.stripUndefinedValuesFromObject({
|
|
15909
15994
|
"metadata:context": include("context") ? meta.context : void 0,
|
|
15910
15995
|
"metadata:etag": include("etag") ? meta.etag : void 0
|
|
@@ -16403,7 +16488,14 @@ class ResourcefulModelController2 {
|
|
|
16403
16488
|
if (!(relationship in record)) {
|
|
16404
16489
|
throw new errors$1.E_RELATIONSHIP_NOT_FOUND_EXCEPTION();
|
|
16405
16490
|
}
|
|
16406
|
-
|
|
16491
|
+
let value = record[relationship];
|
|
16492
|
+
const propertyDefinition = model.$resourcefulColumns.get(relationship) ?? model.$resourcefulComputedAccessors.get(relationship);
|
|
16493
|
+
const columnType = propertyDefinition?.type;
|
|
16494
|
+
const dateKind = type_guardsDMqlMT2e.isInstanceOf(columnType, "ResourcefulDateType", definitions.ResourcefulDateType) ? "date" : type_guardsDMqlMT2e.isInstanceOf(columnType, "ResourcefulDateTimeType", definitions.ResourcefulDateTimeType) ? "dateTime" : void 0;
|
|
16495
|
+
if (dateKind) {
|
|
16496
|
+
const coerced = coerceDateValueToRange(value, dateKind, propertyDefinition.nullable);
|
|
16497
|
+
if (coerced !== void 0) value = coerced;
|
|
16498
|
+
}
|
|
16407
16499
|
ctx.response.header("Content-Type", "text/plain; charset=utf-8");
|
|
16408
16500
|
return ctx.response.status(200).send(value === null ? "" : String(value));
|
|
16409
16501
|
}
|
|
@@ -17503,7 +17595,7 @@ async function configure(command) {
|
|
|
17503
17595
|
}
|
|
17504
17596
|
]);
|
|
17505
17597
|
}
|
|
17506
|
-
const version = "0.1.0-master-
|
|
17598
|
+
const version = "0.1.0-master-e5b91a85";
|
|
17507
17599
|
exports.configure = configure;
|
|
17508
17600
|
exports.getResourcefulModelCreatePayloadValidationSchema = getResourcefulModelCreatePayloadValidationSchema;
|
|
17509
17601
|
exports.odataRouterMacro = odataRouterMacro;
|
|
@@ -17518,4 +17610,4 @@ exports.resourcefulManyToMany = resourcefulManyToMany;
|
|
|
17518
17610
|
exports.resourcefulRouterMacro = resourcefulRouterMacro;
|
|
17519
17611
|
exports.version = version;
|
|
17520
17612
|
exports.withResourceful = withResourceful;
|
|
17521
|
-
//# sourceMappingURL=index-
|
|
17613
|
+
//# sourceMappingURL=index-BZfalkrg.cjs.map
|