functional-models 3.9.5 → 3.11.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.
Files changed (84) hide show
  1. package/cjs/errors.cjs +38 -0
  2. package/cjs/errors.cjs.map +7 -0
  3. package/cjs/index.cjs +2426 -0
  4. package/cjs/index.cjs.map +7 -0
  5. package/cjs/lib.cjs +431 -0
  6. package/cjs/lib.cjs.map +7 -0
  7. package/cjs/models.cjs +571 -0
  8. package/cjs/models.cjs.map +7 -0
  9. package/cjs/orm/index.cjs +1765 -0
  10. package/cjs/orm/index.cjs.map +7 -0
  11. package/cjs/orm/internal-libs.cjs +136 -0
  12. package/cjs/orm/internal-libs.cjs.map +7 -0
  13. package/cjs/orm/libs.cjs +88 -0
  14. package/cjs/orm/libs.cjs.map +7 -0
  15. package/cjs/orm/models.cjs +1027 -0
  16. package/cjs/orm/models.cjs.map +7 -0
  17. package/cjs/orm/properties.cjs +989 -0
  18. package/cjs/orm/properties.cjs.map +7 -0
  19. package/cjs/orm/query.cjs +376 -0
  20. package/cjs/orm/query.cjs.map +7 -0
  21. package/cjs/orm/types.cjs +59 -0
  22. package/cjs/orm/types.cjs.map +7 -0
  23. package/cjs/orm/validation.cjs +301 -0
  24. package/cjs/orm/validation.cjs.map +7 -0
  25. package/cjs/properties.cjs +998 -0
  26. package/cjs/properties.cjs.map +7 -0
  27. package/cjs/serialization.cjs +75 -0
  28. package/cjs/serialization.cjs.map +7 -0
  29. package/cjs/types.cjs +65 -0
  30. package/cjs/types.cjs.map +7 -0
  31. package/cjs/utils.cjs +187 -0
  32. package/cjs/utils.cjs.map +7 -0
  33. package/cjs/validation.cjs +431 -0
  34. package/cjs/validation.cjs.map +7 -0
  35. package/errors.js +3 -4
  36. package/errors.js.map +1 -1
  37. package/index.d.ts +13 -13
  38. package/index.js +13 -52
  39. package/index.js.map +1 -1
  40. package/lib.d.ts +5 -5
  41. package/lib.js +45 -65
  42. package/lib.js.map +1 -1
  43. package/models.d.ts +1 -1
  44. package/models.js +22 -30
  45. package/models.js.map +1 -1
  46. package/orm/index.d.ts +9 -9
  47. package/orm/index.js +9 -48
  48. package/orm/index.js.map +1 -1
  49. package/orm/internal-libs.js +7 -11
  50. package/orm/internal-libs.js.map +1 -1
  51. package/orm/libs.d.ts +1 -1
  52. package/orm/libs.js +8 -16
  53. package/orm/libs.js.map +1 -1
  54. package/orm/models.d.ts +2 -2
  55. package/orm/models.js +20 -26
  56. package/orm/models.js.map +1 -1
  57. package/orm/properties.d.ts +28 -28
  58. package/orm/properties.js +28 -36
  59. package/orm/properties.js.map +1 -1
  60. package/orm/query.d.ts +1 -1
  61. package/orm/query.js +31 -52
  62. package/orm/query.js.map +1 -1
  63. package/orm/types.d.ts +2 -2
  64. package/orm/types.js +7 -10
  65. package/orm/types.js.map +1 -1
  66. package/orm/validation.d.ts +2 -2
  67. package/orm/validation.js +5 -13
  68. package/orm/validation.js.map +1 -1
  69. package/package.json +50 -65
  70. package/properties.d.ts +133 -133
  71. package/properties.js +66 -94
  72. package/properties.js.map +1 -1
  73. package/serialization.d.ts +1 -1
  74. package/serialization.js +3 -9
  75. package/serialization.js.map +1 -1
  76. package/types.d.ts +6 -1
  77. package/types.js +4 -6
  78. package/types.js.map +1 -1
  79. package/utils.d.ts +2 -1
  80. package/utils.js +8 -23
  81. package/utils.js.map +1 -1
  82. package/validation.d.ts +1 -1
  83. package/validation.js +19 -50
  84. package/validation.js.map +1 -1
package/cjs/models.cjs ADDED
@@ -0,0 +1,571 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/models.ts
31
+ var models_exports = {};
32
+ __export(models_exports, {
33
+ Model: () => Model,
34
+ isNullRestInfo: () => isNullRestInfo,
35
+ noFetch: () => noFetch
36
+ });
37
+ module.exports = __toCommonJS(models_exports);
38
+ var import_merge4 = __toESM(require("lodash/merge.js"), 1);
39
+ var import_zod2 = __toESM(require("zod"), 1);
40
+
41
+ // src/serialization.ts
42
+ var import_merge = __toESM(require("lodash/merge.js"), 1);
43
+ var isModelInstance = (obj) => {
44
+ return Boolean(obj.toObj);
45
+ };
46
+ var _getValue = async (value) => {
47
+ if (value === void 0) {
48
+ return void 0;
49
+ }
50
+ if (value === null) {
51
+ return null;
52
+ }
53
+ const type = typeof value;
54
+ const asFunction = value;
55
+ if (type === "function") {
56
+ return _getValue(await asFunction());
57
+ }
58
+ if (isModelInstance(value)) {
59
+ return _getValue(await value.toObj());
60
+ }
61
+ const asDate = value;
62
+ if (type === "object" && asDate.toISOString) {
63
+ return _getValue(asDate.toISOString());
64
+ }
65
+ return value;
66
+ };
67
+ var toJsonAble = (keyToFunc) => () => {
68
+ return Object.entries(keyToFunc).reduce(async (acc, [key, value]) => {
69
+ const realAcc = await acc;
70
+ const trueValue = await _getValue(await value);
71
+ if (trueValue === void 0) {
72
+ return realAcc;
73
+ }
74
+ return (0, import_merge.default)(realAcc, { [key]: trueValue });
75
+ }, Promise.resolve({}));
76
+ };
77
+
78
+ // src/validation.ts
79
+ var import_isEmpty = __toESM(require("lodash/isEmpty.js"), 1);
80
+ var import_merge2 = __toESM(require("lodash/merge.js"), 1);
81
+ var import_flatMap = __toESM(require("lodash/flatMap.js"), 1);
82
+ var import_get = __toESM(require("lodash/get.js"), 1);
83
+
84
+ // src/types.ts
85
+ var ApiMethod = /* @__PURE__ */ ((ApiMethod2) => {
86
+ ApiMethod2["create"] = "create";
87
+ ApiMethod2["retrieve"] = "retrieve";
88
+ ApiMethod2["update"] = "update";
89
+ ApiMethod2["delete"] = "delete";
90
+ ApiMethod2["search"] = "search";
91
+ return ApiMethod2;
92
+ })(ApiMethod || {});
93
+
94
+ // src/utils.ts
95
+ var import_async_lock = __toESM(require("async-lock"), 1);
96
+
97
+ // node_modules/uuid/dist-node/stringify.js
98
+ var byteToHex = [];
99
+ for (let i = 0; i < 256; ++i) {
100
+ byteToHex.push((i + 256).toString(16).slice(1));
101
+ }
102
+ function unsafeStringify(arr, offset = 0) {
103
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
104
+ }
105
+
106
+ // node_modules/uuid/dist-node/rng.js
107
+ var rnds8 = new Uint8Array(16);
108
+ function rng() {
109
+ return crypto.getRandomValues(rnds8);
110
+ }
111
+
112
+ // node_modules/uuid/dist-node/v4.js
113
+ function v4(options, buf, offset) {
114
+ if (!buf && !options && crypto.randomUUID) {
115
+ return crypto.randomUUID();
116
+ }
117
+ return _v4(options, buf, offset);
118
+ }
119
+ function _v4(options, buf, offset) {
120
+ options = options || {};
121
+ const rnds = options.random ?? options.rng?.() ?? rng();
122
+ if (rnds.length < 16) {
123
+ throw new Error("Random bytes length must be >= 16");
124
+ }
125
+ rnds[6] = rnds[6] & 15 | 64;
126
+ rnds[8] = rnds[8] & 63 | 128;
127
+ if (buf) {
128
+ offset = offset || 0;
129
+ if (offset < 0 || offset + 16 > buf.length) {
130
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
131
+ }
132
+ for (let i = 0; i < 16; ++i) {
133
+ buf[offset + i] = rnds[i];
134
+ }
135
+ return buf;
136
+ }
137
+ return unsafeStringify(rnds);
138
+ }
139
+ var v4_default = v4;
140
+
141
+ // src/utils.ts
142
+ var import_get_random_values = __toESM(require("get-random-values"), 1);
143
+ var toTitleCase = (string) => {
144
+ return `${string.slice(0, 1).toUpperCase()}${string.slice(1)}`;
145
+ };
146
+ var PluralEndings = /* @__PURE__ */ ((PluralEndings2) => {
147
+ PluralEndings2["ves"] = "fe";
148
+ PluralEndings2["ies"] = "y";
149
+ PluralEndings2["i"] = "us";
150
+ PluralEndings2["zes"] = "ze";
151
+ PluralEndings2["ses"] = "s";
152
+ PluralEndings2["es"] = "e";
153
+ PluralEndings2["s"] = "";
154
+ return PluralEndings2;
155
+ })(PluralEndings || {});
156
+ var _singularizingRe = new RegExp(
157
+ `(${Object.keys(PluralEndings).join("|")})$`,
158
+ "u"
159
+ );
160
+ var singularize = (word) => {
161
+ return word.replace(_singularizingRe, (r) => PluralEndings[r]);
162
+ };
163
+ var flowFindFirst = (funcs) => (input) => {
164
+ return funcs.reduce((acc, func) => {
165
+ if (acc) {
166
+ return acc;
167
+ }
168
+ return func(input);
169
+ }, void 0);
170
+ };
171
+ var memoizeSync = (method) => {
172
+ let value = void 0;
173
+ let called = false;
174
+ return (...args) => {
175
+ if (!called) {
176
+ called = true;
177
+ value = method(...args);
178
+ }
179
+ return value;
180
+ };
181
+ };
182
+ var memoizeAsync = (method) => {
183
+ const key = v4_default();
184
+ const lock = new import_async_lock.default();
185
+ let value = void 0;
186
+ let called = false;
187
+ return async (...args) => {
188
+ return lock.acquire(key, async () => {
189
+ if (!called) {
190
+ called = true;
191
+ value = await method(...args);
192
+ }
193
+ return value;
194
+ });
195
+ };
196
+ };
197
+
198
+ // src/validation.ts
199
+ var multiValidator = (validators) => {
200
+ const flow2 = flowFindFirst(
201
+ validators
202
+ );
203
+ return flow2;
204
+ };
205
+ var _trueOrError = (method, error) => (value) => {
206
+ if (method(value) === false) {
207
+ return error;
208
+ }
209
+ return void 0;
210
+ };
211
+ var _typeOrError = (type, errorMessage) => (value) => {
212
+ if (typeof value !== type) {
213
+ return errorMessage;
214
+ }
215
+ return void 0;
216
+ };
217
+ var isType = (type) => (value) => {
218
+ return _typeOrError(type, `Must be a ${type}`)(value);
219
+ };
220
+ var isNumber = isType("number");
221
+ var isInteger = _trueOrError(Number.isInteger, "Must be an integer");
222
+ var isObject = multiValidator([
223
+ isType("object"),
224
+ (x) => Array.isArray(x) ? "Must be an object, but got an array" : void 0
225
+ ]);
226
+ var isBoolean = isType("boolean");
227
+ var isString = isType("string");
228
+ var isArray = _trueOrError(
229
+ (v) => Array.isArray(v),
230
+ "Value is not an array"
231
+ );
232
+ var PRIMITIVE_TO_SPECIAL_TYPE_VALIDATOR = {
233
+ ["boolean" /* boolean */]: isBoolean,
234
+ ["string" /* string */]: isString,
235
+ ["integer" /* integer */]: isInteger,
236
+ ["number" /* number */]: isNumber,
237
+ ["object" /* object */]: isObject
238
+ };
239
+ var createModelValidator = (validators, modelValidators) => {
240
+ const _modelValidator = async (instance, propertyConfiguration) => {
241
+ return Promise.resolve().then(async () => {
242
+ if (!instance) {
243
+ throw new Error(`Instance cannot be empty`);
244
+ }
245
+ const model = instance.getModel();
246
+ const keysAndFunctions = Object.entries(validators);
247
+ const instanceData = await instance.toObj();
248
+ const propertyValidationErrors = await Promise.all(
249
+ keysAndFunctions.map(async ([key, validator]) => {
250
+ return [
251
+ key,
252
+ await validator(model, instanceData, propertyConfiguration)
253
+ ];
254
+ })
255
+ );
256
+ const modelValidationErrors = (await Promise.all(
257
+ modelValidators ? modelValidators.map((validator) => {
258
+ return validator(model, instanceData, propertyConfiguration);
259
+ }) : []
260
+ )).filter((x) => x);
261
+ const propertyErrors = propertyValidationErrors.filter(([, errors]) => Boolean(errors) && errors.length > 0).reduce((acc, [key, errors]) => {
262
+ return (0, import_merge2.default)(acc, { [String(key)]: errors });
263
+ }, {});
264
+ const final = modelValidationErrors.length > 0 ? (0, import_merge2.default)(propertyErrors, { overall: modelValidationErrors }) : propertyErrors;
265
+ if ((0, import_isEmpty.default)(final)) {
266
+ return void 0;
267
+ }
268
+ return final;
269
+ });
270
+ };
271
+ return _modelValidator;
272
+ };
273
+
274
+ // src/lib.ts
275
+ var import_openapi_types = require("openapi-types");
276
+ var import_kebabCase = __toESM(require("lodash/kebabCase.js"), 1);
277
+ var import_flow = __toESM(require("lodash/flow.js"), 1);
278
+ var import_merge3 = __toESM(require("lodash/merge.js"), 1);
279
+ var import_get2 = __toESM(require("lodash/get.js"), 1);
280
+ var import_zod = require("zod");
281
+ var HttpMethods = import_openapi_types.OpenAPIV3.HttpMethods;
282
+ var NULL_ENDPOINT = "NULL";
283
+ var NULL_METHOD = HttpMethods.HEAD;
284
+ var ID_KEY = ":id";
285
+ var getModelName = (namespace, pluralName) => {
286
+ return `${namespace}/${pluralName}`;
287
+ };
288
+ var buildValidEndpoint = (...components) => {
289
+ const suffix = components.map((x) => {
290
+ if (x === ID_KEY) {
291
+ return x;
292
+ }
293
+ return (0, import_kebabCase.default)(x);
294
+ }).map((s) => s.toLowerCase()).join("/");
295
+ return `/${suffix}`;
296
+ };
297
+ var _generateRestInfo = (method, withId, ...additional) => (pluralName, namespace) => (existing) => {
298
+ if (existing) {
299
+ return {
300
+ // Default add security, then override it.
301
+ security: {},
302
+ ...existing
303
+ };
304
+ }
305
+ const endpoint = withId ? buildValidEndpoint(namespace, pluralName, ID_KEY) : buildValidEndpoint(namespace, pluralName, ...additional);
306
+ return {
307
+ method,
308
+ endpoint,
309
+ // We cannot auto create security.
310
+ security: {}
311
+ };
312
+ };
313
+ var _apiMethodToRestInfoGenerator = {
314
+ ["create" /* create */]: _generateRestInfo(HttpMethods.POST, false),
315
+ ["retrieve" /* retrieve */]: _generateRestInfo(HttpMethods.GET, true),
316
+ ["update" /* update */]: _generateRestInfo(HttpMethods.PUT, true),
317
+ ["delete" /* delete */]: _generateRestInfo(HttpMethods.DELETE, true),
318
+ ["search" /* search */]: _generateRestInfo(HttpMethods.POST, false, "search")
319
+ };
320
+ var getNullRestInfo = () => {
321
+ return {
322
+ endpoint: NULL_ENDPOINT,
323
+ method: NULL_METHOD,
324
+ security: {}
325
+ };
326
+ };
327
+ var _fillOutRestInfo = (pluralName, namespace, partial, nullRest) => {
328
+ const finishedRestInfo = Object.entries(
329
+ ApiMethod
330
+ ).reduce(
331
+ (acc, [, method]) => {
332
+ const existing = partial && partial.rest && partial.rest[method] ? partial.rest[method] : void 0;
333
+ const restInfo = _apiMethodToRestInfoGenerator[method](
334
+ pluralName,
335
+ namespace
336
+ )(existing);
337
+ return (0, import_merge3.default)(acc, {
338
+ [method]: restInfo
339
+ });
340
+ },
341
+ nullRest
342
+ );
343
+ return {
344
+ noPublish: false,
345
+ onlyPublish: [],
346
+ rest: finishedRestInfo,
347
+ createOnlyOne: partial?.createOnlyOne || false
348
+ };
349
+ };
350
+ var populateApiInformation = (pluralName, namespace, partial) => {
351
+ const nullRest = {
352
+ delete: getNullRestInfo(),
353
+ search: getNullRestInfo(),
354
+ update: getNullRestInfo(),
355
+ retrieve: getNullRestInfo(),
356
+ create: getNullRestInfo()
357
+ };
358
+ if (!partial) {
359
+ return _fillOutRestInfo(pluralName, namespace, partial, nullRest);
360
+ }
361
+ if (partial.noPublish) {
362
+ return {
363
+ onlyPublish: [],
364
+ noPublish: true,
365
+ rest: nullRest,
366
+ createOnlyOne: false
367
+ };
368
+ }
369
+ const rest = partial.rest || {};
370
+ if (partial.onlyPublish && partial.onlyPublish.length > 0) {
371
+ return partial.onlyPublish.reduce(
372
+ (acc, method) => {
373
+ const restInfo = _apiMethodToRestInfoGenerator[method](
374
+ pluralName,
375
+ namespace
376
+ )(rest[method]);
377
+ return (0, import_merge3.default)(acc, {
378
+ rest: {
379
+ [method]: restInfo
380
+ }
381
+ });
382
+ },
383
+ {
384
+ noPublish: false,
385
+ onlyPublish: partial.onlyPublish,
386
+ createOnlyOne: Boolean(partial.createOnlyOne),
387
+ rest: nullRest
388
+ }
389
+ );
390
+ }
391
+ return _fillOutRestInfo(pluralName, namespace, partial, nullRest);
392
+ };
393
+
394
+ // src/models.ts
395
+ var _defaultOptions = () => ({
396
+ instanceCreatedCallback: void 0
397
+ });
398
+ var _convertOptions = (options) => {
399
+ const r = (0, import_merge4.default)({}, _defaultOptions(), options);
400
+ return r;
401
+ };
402
+ var _addDescription = (schema, description) => {
403
+ if (!description) {
404
+ return schema;
405
+ }
406
+ if (typeof schema.openapi === "function") {
407
+ return schema.openapi({ description });
408
+ }
409
+ return schema.meta ? schema.meta({ description }) : schema.describe(description);
410
+ };
411
+ var _createZod = (modelDefinition) => {
412
+ if (modelDefinition.schema) {
413
+ return _addDescription(modelDefinition.schema, modelDefinition.description);
414
+ }
415
+ const properties = Object.entries(modelDefinition.properties).reduce(
416
+ (acc, [key, property]) => {
417
+ const asProp = property;
418
+ return (0, import_merge4.default)(acc, {
419
+ [key]: asProp.getZod()
420
+ });
421
+ },
422
+ {}
423
+ );
424
+ const obj = import_zod2.default.object(properties);
425
+ return _addDescription(obj, modelDefinition.description);
426
+ };
427
+ var _toModelDefinition = (minimal) => {
428
+ return {
429
+ singularName: singularize(minimal.pluralName),
430
+ displayName: toTitleCase(minimal.pluralName),
431
+ description: "",
432
+ primaryKeyName: "id",
433
+ modelValidators: [],
434
+ schema: _createZod(minimal),
435
+ ...minimal
436
+ };
437
+ };
438
+ var _validateModelDefinition = (modelDefinition) => {
439
+ const primaryKeyName = modelDefinition.primaryKeyName || "id";
440
+ const primaryKeyProperty = (
441
+ // @ts-ignore
442
+ modelDefinition.properties[primaryKeyName]
443
+ );
444
+ if (!primaryKeyProperty) {
445
+ throw new Error(`Property missing for primaryKey named ${primaryKeyName}`);
446
+ }
447
+ if (!modelDefinition.pluralName) {
448
+ throw new Error(`Must include pluralName for model.`);
449
+ }
450
+ if (!modelDefinition.namespace) {
451
+ throw new Error(`Must include namespace for model.`);
452
+ }
453
+ };
454
+ var Model = (minimalModelDefinitions, options) => {
455
+ _validateModelDefinition(minimalModelDefinitions);
456
+ let model = null;
457
+ const theOptions = _convertOptions(options);
458
+ const modelDefinition = _toModelDefinition(minimalModelDefinitions);
459
+ const getPrimaryKeyName = () => modelDefinition.primaryKeyName;
460
+ const getPrimaryKey = (loadedInternals) => {
461
+ const property = loadedInternals.get[getPrimaryKeyName()];
462
+ return property();
463
+ };
464
+ const create = (instanceValues) => {
465
+ let instance = null;
466
+ const startingInternals = {
467
+ get: {},
468
+ validators: {},
469
+ references: {}
470
+ };
471
+ const prop = Object.entries(
472
+ modelDefinition.properties
473
+ );
474
+ const loadedInternals = prop.reduce(
475
+ (acc, [key, property]) => {
476
+ const propertyGetter = memoizeSync(
477
+ () => property.createGetter(
478
+ //@ts-ignore
479
+ instanceValues[key],
480
+ instanceValues,
481
+ // NOTE: By the time it gets here, it has already been implemented.
482
+ instance
483
+ )()
484
+ );
485
+ const propertyValidator = property.getValidator(propertyGetter);
486
+ const fleshedOutInstanceProperties = {
487
+ get: {
488
+ [key]: () => propertyGetter()
489
+ },
490
+ validators: {
491
+ [key]: propertyValidator
492
+ }
493
+ };
494
+ const asReferenced = property;
495
+ const referencedProperty = asReferenced.getReferencedId ? {
496
+ references: {
497
+ [key]: () => asReferenced.getReferencedId(
498
+ // @ts-ignore
499
+ instanceValues[key]
500
+ )
501
+ }
502
+ } : {};
503
+ return (0, import_merge4.default)(
504
+ acc,
505
+ fleshedOutInstanceProperties,
506
+ referencedProperty
507
+ );
508
+ },
509
+ startingInternals
510
+ );
511
+ const getModel = () => model;
512
+ const toObj = memoizeAsync(() => {
513
+ return toJsonAble(loadedInternals.get)();
514
+ });
515
+ const validate = memoizeAsync((options2 = {}) => {
516
+ return Promise.resolve().then(() => {
517
+ return createModelValidator(
518
+ loadedInternals.validators,
519
+ modelDefinition.modelValidators
520
+ )(instance, options2);
521
+ });
522
+ });
523
+ const getReferences = () => loadedInternals.references;
524
+ const getValidators = () => loadedInternals.validators;
525
+ instance = {
526
+ get: loadedInternals.get,
527
+ getReferences,
528
+ getValidators,
529
+ getModel,
530
+ toObj,
531
+ getPrimaryKey: () => getPrimaryKey(loadedInternals),
532
+ validate
533
+ };
534
+ if (theOptions.instanceCreatedCallback) {
535
+ const toCall = Array.isArray(theOptions.instanceCreatedCallback) ? theOptions.instanceCreatedCallback : [theOptions.instanceCreatedCallback];
536
+ toCall.map((func) => func(instance));
537
+ }
538
+ return instance;
539
+ };
540
+ const getApiInfo = memoizeSync(() => {
541
+ return populateApiInformation(
542
+ modelDefinition.pluralName,
543
+ modelDefinition.namespace,
544
+ modelDefinition.api
545
+ );
546
+ });
547
+ model = {
548
+ /**
549
+ * Creates a model instance.
550
+ */
551
+ create,
552
+ getName: () => getModelName(modelDefinition.namespace, modelDefinition.pluralName),
553
+ getModelDefinition: memoizeSync(() => modelDefinition),
554
+ getPrimaryKey,
555
+ getApiInfo
556
+ };
557
+ return model;
558
+ };
559
+ var isNullRestInfo = (restInfo) => {
560
+ return restInfo.method === NULL_METHOD && restInfo.endpoint === NULL_ENDPOINT;
561
+ };
562
+ var noFetch = () => {
563
+ return Promise.resolve(void 0);
564
+ };
565
+ // Annotate the CommonJS export names for ESM import in node:
566
+ 0 && (module.exports = {
567
+ Model,
568
+ isNullRestInfo,
569
+ noFetch
570
+ });
571
+ //# sourceMappingURL=models.cjs.map