functional-models 1.1.3 → 1.1.4

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 (103) hide show
  1. package/package.json +5 -4
  2. package/{dist/src → src}/constants.d.ts +0 -0
  3. package/{dist/src → src}/constants.js +0 -0
  4. package/{dist/src → src}/constants.js.map +0 -0
  5. package/{dist/src → src}/errors.d.ts +0 -0
  6. package/{dist/src → src}/errors.js +0 -0
  7. package/{dist/src → src}/errors.js.map +0 -0
  8. package/{dist/src → src}/index.d.ts +0 -0
  9. package/{dist/src → src}/index.js +0 -0
  10. package/{dist/src → src}/index.js.map +0 -0
  11. package/{dist/src → src}/interfaces.d.ts +0 -0
  12. package/{dist/src → src}/interfaces.js +0 -0
  13. package/{dist/src → src}/interfaces.js.map +0 -0
  14. package/{dist/src → src}/lazy.d.ts +0 -0
  15. package/{dist/src → src}/lazy.js +0 -0
  16. package/{dist/src → src}/lazy.js.map +0 -0
  17. package/{dist/src → src}/methods.d.ts +0 -0
  18. package/{dist/src → src}/methods.js +0 -0
  19. package/{dist/src → src}/methods.js.map +0 -0
  20. package/{dist/src → src}/models.d.ts +0 -0
  21. package/{dist/src → src}/models.js +0 -0
  22. package/{dist/src → src}/models.js.map +0 -0
  23. package/{dist/src → src}/properties.d.ts +0 -0
  24. package/{dist/src → src}/properties.js +0 -0
  25. package/{dist/src → src}/properties.js.map +0 -0
  26. package/{dist/src → src}/serialization.d.ts +0 -0
  27. package/{dist/src → src}/serialization.js +0 -0
  28. package/{dist/src → src}/serialization.js.map +0 -0
  29. package/{dist/src → src}/utils.d.ts +0 -0
  30. package/{dist/src → src}/utils.js +0 -0
  31. package/{dist/src → src}/utils.js.map +0 -0
  32. package/{dist/src → src}/validation.d.ts +0 -0
  33. package/{dist/src → src}/validation.js +0 -0
  34. package/{dist/src → src}/validation.js.map +0 -0
  35. package/{dist/stepDefinitions → stepDefinitions}/oldSteps.d.ts +0 -0
  36. package/{dist/stepDefinitions → stepDefinitions}/oldSteps.js +0 -0
  37. package/{dist/stepDefinitions → stepDefinitions}/oldSteps.js.map +0 -0
  38. package/{dist/stepDefinitions → stepDefinitions}/tssteps.d.ts +0 -0
  39. package/{dist/stepDefinitions → stepDefinitions}/tssteps.js +0 -0
  40. package/{dist/stepDefinitions → stepDefinitions}/tssteps.js.map +0 -0
  41. package/{dist/test → test}/src/errors.test.d.ts +0 -0
  42. package/{dist/test → test}/src/errors.test.js +0 -0
  43. package/{dist/test → test}/src/errors.test.js.map +0 -0
  44. package/{dist/test/src/lazy.test.d.ts → test/src/index.test.d.ts} +0 -0
  45. package/test/src/index.test.js +3 -0
  46. package/test/src/index.test.js.map +1 -0
  47. package/{dist/test/src/methods.test.d.ts → test/src/lazy.test.d.ts} +0 -0
  48. package/{dist/test → test}/src/lazy.test.js +0 -0
  49. package/{dist/test → test}/src/lazy.test.js.map +0 -0
  50. package/{dist/test/src/models.test.d.ts → test/src/methods.test.d.ts} +0 -0
  51. package/{dist/test → test}/src/methods.test.js +0 -0
  52. package/{dist/test → test}/src/methods.test.js.map +0 -0
  53. package/{dist/test/src/properties.test.d.ts → test/src/models.test.d.ts} +0 -0
  54. package/{dist/test → test}/src/models.test.js +0 -0
  55. package/{dist/test → test}/src/models.test.js.map +0 -0
  56. package/{dist/test/src/serialization.test.d.ts → test/src/properties.test.d.ts} +0 -0
  57. package/{dist/test → test}/src/properties.test.js +0 -0
  58. package/{dist/test → test}/src/properties.test.js.map +0 -0
  59. package/{dist/test/src/utils.test.d.ts → test/src/serialization.test.d.ts} +0 -0
  60. package/{dist/test → test}/src/serialization.test.js +0 -0
  61. package/{dist/test → test}/src/serialization.test.js.map +0 -0
  62. package/{dist/test/src/validation.test.d.ts → test/src/utils.test.d.ts} +0 -0
  63. package/{dist/test → test}/src/utils.test.js +0 -0
  64. package/{dist/test → test}/src/utils.test.js.map +0 -0
  65. package/test/src/validation.test.d.ts +1 -0
  66. package/{dist/test → test}/src/validation.test.js +0 -0
  67. package/{dist/test → test}/src/validation.test.js.map +0 -0
  68. package/.eslintignore +0 -5
  69. package/.eslintrc +0 -180
  70. package/.github/workflows/feature.yml +0 -26
  71. package/.github/workflows/ut.yml +0 -32
  72. package/.prettierignore +0 -7
  73. package/.prettierrc.json +0 -14
  74. package/LICENSE +0 -674
  75. package/cucumber.js +0 -10
  76. package/features/arrayFields.feature +0 -52
  77. package/features/basic-ts.feature +0 -13
  78. package/features/functions.feature +0 -10
  79. package/features/model.feature +0 -7
  80. package/features/validation.feature +0 -12
  81. package/index.js +0 -1
  82. package/src/constants.ts +0 -15
  83. package/src/errors.ts +0 -18
  84. package/src/index.ts +0 -12
  85. package/src/interfaces.ts +0 -323
  86. package/src/lazy.ts +0 -24
  87. package/src/methods.ts +0 -30
  88. package/src/models.ts +0 -183
  89. package/src/properties.ts +0 -375
  90. package/src/serialization.ts +0 -39
  91. package/src/utils.ts +0 -42
  92. package/src/validation.ts +0 -390
  93. package/stepDefinitions/oldSteps.ts +0 -216
  94. package/stepDefinitions/tssteps.ts +0 -107
  95. package/test/src/errors.test.ts +0 -31
  96. package/test/src/lazy.test.ts +0 -15
  97. package/test/src/methods.test.ts +0 -45
  98. package/test/src/models.test.ts +0 -417
  99. package/test/src/properties.test.ts +0 -747
  100. package/test/src/serialization.test.ts +0 -80
  101. package/test/src/utils.test.ts +0 -76
  102. package/test/src/validation.test.ts +0 -682
  103. package/tsconfig.json +0 -100
package/cucumber.js DELETED
@@ -1,10 +0,0 @@
1
- const common = [
2
- 'features/**/*.feature',
3
- '--require-module ts-node/register',
4
- '--require ./stepDefinitions/*.ts',
5
- '--format progress-bar',
6
- ].join(' ')
7
-
8
- module.exports = {
9
- default: common,
10
- }
@@ -1,52 +0,0 @@
1
- Feature: Array Property
2
-
3
- Scenario: A model that has an array property is created holding an array of integers and is checked and validated
4
- Given ArrayModel1 model is used
5
- When ArrayModelData1 data is inserted
6
- Then the ArrayProperty property is called on the model
7
- Then the array values match
8
- | array | [1,2,3,4,5]|
9
- Then functions.validate is called
10
- Then an array of 0 errors is shown
11
-
12
- Scenario: A model that has an array property but has a non-array inserted into it fails validation
13
- Given ArrayModel1 model is used
14
- When ArrayModelData2 data is inserted
15
- Then the ArrayProperty property is called on the model
16
- Then functions.validate is called
17
- Then an array of 1 errors is shown
18
-
19
- Scenario: A model that has an array property for integers but an array of strings is inserted into it, it should fail validation
20
- Given ArrayModel1 model is used
21
- When ArrayModelData3 data is inserted
22
- Then the ArrayProperty property is called on the model
23
- Then functions.validate is called
24
- Then an array of 1 errors is shown
25
-
26
- Scenario: A model that has an array property that has mixed values it should not fail validation.
27
- Given ArrayModel2 model is used
28
- When ArrayModelData4 data is inserted
29
- Then the ArrayProperty property is called on the model
30
- Then functions.validate is called
31
- Then an array of 0 errors is shown
32
-
33
- Scenario: A model that uses the arrayProperty property that has mixed values it should not fail validation.
34
- Given ArrayModel3 model is used
35
- When ArrayModelData4 data is inserted
36
- Then the ArrayProperty property is called on the model
37
- Then functions.validate is called
38
- Then an array of 0 errors is shown
39
-
40
- Scenario: A model that uses the arrayProperty with the choice validator should pass validation with no errors.
41
- Given ArrayModel4 model is used
42
- When ArrayModelData5 data is inserted
43
- Then the ArrayProperty property is called on the model
44
- Then functions.validate is called
45
- Then an array of 0 errors is shown
46
-
47
- Scenario: A model that uses the arrayProperty with the choice validator should fail validation when one value is outside the choices
48
- Given ArrayModel4 model is used
49
- When ArrayModelData6 data is inserted
50
- Then the ArrayProperty property is called on the model
51
- Then functions.validate is called
52
- Then an array of 1 errors is shown
@@ -1,13 +0,0 @@
1
- Feature: Basic Typescript
2
-
3
- Scenario: A model with properties, instance methods, and model methods works as expected.
4
- Given model TE_FULL_TEST is used
5
- When a model instanced is created is called on model with TE_FULL_TEST_1
6
- And toObj is called on the model instance
7
- And instance method myMethod is called
8
- And model method myModelMethod is called
9
- And validate is called on model instance
10
- Then the results match TE_FULL_TEST_1 obj data
11
- And the result of instance method is InstanceMethod
12
- And the result of model method is ModelMethod
13
- And the model instance validated successfully
@@ -1,10 +0,0 @@
1
- Feature: Functions
2
-
3
- Scenario: A model with 2 properties (name, id), 2 model functions (modelWrapper, toString), and 2 instance functions (toString, toJson)
4
- Given FunctionModel1 model is used
5
- When FunctionModelData1 data is inserted
6
- Then name property is found
7
- And id property is found
8
- And toString instance function is found
9
- And toJson instance function is found
10
- And modelWrapper model function is found
@@ -1,7 +0,0 @@
1
- Feature: Models
2
-
3
- Scenario: A Model With 4 properties
4
- Given TestModel1 model is used
5
- When TestModel1b data is inserted
6
- Then TestModel1b expected property is found
7
-
@@ -1,12 +0,0 @@
1
- Feature: Validation
2
-
3
- Scenario: Creating TestModel1 with required arguments but not having them.
4
- Given the TestModel1 has been created, with TestModel1a inputs provided
5
- When functions.validate is called
6
- Then an array of 2 errors is shown
7
-
8
- Scenario: Creating TestModel1 with required arguments and having them.
9
- Given the TestModel1 has been created, with TestModel1b inputs provided
10
- When functions.validate is called
11
- Then an array of 0 errors is shown
12
-
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./src/index')
package/src/constants.ts DELETED
@@ -1,15 +0,0 @@
1
- enum PROPERTY_TYPES {
2
- UniqueId = 'UniqueId',
3
- DateProperty = 'DateProperty',
4
- ArrayProperty = 'ArrayProperty',
5
- ReferenceProperty = 'ReferenceProperty',
6
- IntegerProperty = 'IntegerProperty',
7
- TextProperty = 'TextProperty',
8
- ConstantValueProperty = 'ConstantValueProperty',
9
- NumberProperty = 'NumberProperty',
10
- ObjectProperty = 'ObjectProperty',
11
- EmailProperty = 'EmailProperty',
12
- BooleanProperty = 'BooleanProperty',
13
- }
14
-
15
- export { PROPERTY_TYPES }
package/src/errors.ts DELETED
@@ -1,18 +0,0 @@
1
- type KeysToErrors = { [s: string]: string[] }
2
-
3
- /* eslint-disable functional/no-this-expression */
4
- /* eslint-disable functional/no-class */
5
- class ValidationError extends Error {
6
- public modelName: String
7
- public keysToErrors: KeysToErrors
8
- constructor(modelName: String, keysToErrors: KeysToErrors) {
9
- super(`${modelName} did not pass validation`)
10
- this.name = 'ValidationError'
11
- this.modelName = modelName
12
- this.keysToErrors = keysToErrors
13
- }
14
- }
15
- /* eslint-enable functional/no-this-expression */
16
- /* eslint-enable functional/no-class */
17
-
18
- export { ValidationError }
package/src/index.ts DELETED
@@ -1,12 +0,0 @@
1
- import * as constants from './constants'
2
- import * as errors from './errors'
3
- import * as validation from './validation'
4
- import * as serialization from './serialization'
5
- import * as utils from './utils'
6
- import * as interfaces from './interfaces'
7
-
8
- export * from './models'
9
- export * from './properties'
10
- export * from './methods'
11
-
12
- export { constants, errors, validation, serialization, utils, interfaces }
package/src/interfaces.ts DELETED
@@ -1,323 +0,0 @@
1
- /* eslint-disable no-unused-vars */
2
-
3
- type MaybeFunction<T> = T | (() => T)
4
- type MaybePromise<T> = T | Promise<T>
5
- type Nullable<T> = T | null
6
- type Maybe<T> = T | undefined | null
7
- type Arrayable<T> = T | readonly T[]
8
- type MaybeLazy<T> = Maybe<Promise<T>>
9
- type MaybeEmpty<T> = T | null | undefined
10
- type JsonAble =
11
- | number
12
- | string
13
- | boolean
14
- | null
15
- | Arrayable<{ readonly [s: string]: JsonAble }>
16
- type VeryPrimitivesTypes = null | string | number | boolean
17
- type toObj = () => Promise<JsonAble>
18
-
19
- type ValueIsOfType<T, V> = {
20
- readonly [P in keyof T as T[P] extends V ? P : never]: T[P]
21
- }
22
-
23
- type ValueIsNotOfType<T, V> = {
24
- readonly [P in keyof T as T[P] extends V ? never : P]: T[P]
25
- }
26
-
27
- type InstanceMethodGetters<T> = {
28
- readonly [P in keyof T as T[P] extends ModelInstanceMethod
29
- ? P
30
- : never]: ModelInstanceMethodClient
31
- }
32
-
33
- type ModelMethodGetters<T> = {
34
- readonly [P in keyof T as T[P] extends ModelMethod
35
- ? P
36
- : never]: ModelMethodClient
37
- }
38
-
39
- type ModelMethodTypes<T extends FunctionalModel> =
40
- | ModelMethod
41
- | ModelInstanceMethod
42
- | ModelMethodTyped<T>
43
- | ModelInstanceMethodTyped<T>
44
-
45
- type PropertyGetters<T extends FunctionalModel> = {
46
- readonly // NOTE: This is NOT ModelMethodTypes, its getting everything but.
47
- [Property in keyof T as T[Property] extends ModelMethodTypes<T>
48
- ? never
49
- : Property]: () => T[Property] | Promise<T[Property]>
50
- }
51
-
52
- type FunctionalModel =
53
- | {
54
- readonly [s: string]:
55
- | Arrayable<number>
56
- | Arrayable<string>
57
- | Arrayable<boolean>
58
- | Arrayable<null>
59
- | Arrayable<FunctionalModel>
60
- | Arrayable<Date>
61
- | Arrayable<undefined>
62
- | ReferenceValueType<any>
63
- | ModelInstanceMethod
64
- | ModelMethod
65
- }
66
- | JsonAble
67
-
68
- type FunctionalType =
69
- | JsonAble
70
- | (() => FunctionalType)
71
- | Arrayable<undefined>
72
- | Arrayable<Date>
73
- | Arrayable<FunctionalModel>
74
- | Arrayable<{ readonly [s: string]: JsonAble }>
75
-
76
- type ModelInstanceInputData<T extends FunctionalModel> = ValueIsNotOfType<
77
- T,
78
- ModelMethodTypes<T>
79
- >
80
-
81
- type PropertyValidatorComponentTypeAdvanced<
82
- TValue,
83
- TModel extends FunctionalModel
84
- > = (
85
- value: TValue,
86
- instance: ModelInstance<TModel>,
87
- instanceData: FunctionalModel
88
- ) => string | undefined
89
-
90
- type PropertyValidatorComponentType<TValue> = (
91
- value: TValue,
92
- instance: ModelInstance<any>,
93
- instanceData: FunctionalModel
94
- ) => string | undefined
95
-
96
- type PropertyValidatorComponentSync = PropertyValidatorComponentType<any>
97
-
98
- type PropertyValidatorComponentAsync = (
99
- value: Arrayable<FunctionalModel>,
100
- instance: ModelInstance<any>,
101
- instanceData: FunctionalModel
102
- ) => Promise<string | undefined>
103
-
104
- type PropertyValidatorComponent =
105
- | PropertyValidatorComponentSync
106
- | PropertyValidatorComponentAsync
107
-
108
- type PropertyValidator = (
109
- instance: ModelInstance<any>,
110
- instanceData: FunctionalModel
111
- ) => Promise<ValidationErrors>
112
-
113
- type ValidationError = string | undefined
114
- type ValidationErrors = readonly ValidationError[]
115
- type ModelError = string
116
- type ModelErrors = {
117
- readonly [s: string]: readonly ModelError[]
118
- }
119
-
120
- type ModelComponentValidator = (
121
- instance: ModelInstance<any>,
122
- instanceData: FunctionalModel,
123
- options?: object
124
- ) => Promise<ValidationErrors>
125
-
126
- type ValueGetter = () =>
127
- | MaybePromise<Arrayable<FunctionalType>>
128
- | MaybePromise<ModelInstance<any>>
129
-
130
- type PropertyInstance<T extends Arrayable<FunctionalType>> = {
131
- readonly getConfig: () => object
132
- readonly getChoices: () => readonly VeryPrimitivesTypes[]
133
- readonly getDefaultValue: () => T
134
- readonly getConstantValue: () => T
135
- readonly getPropertyType: () => string
136
- readonly createGetter: (value: T) => ValueGetter
137
- readonly getValidator: (valueGetter: ValueGetter) => PropertyValidator
138
- }
139
-
140
- type PropertiesList<T> = {
141
- readonly [P in keyof T as T[P] extends Arrayable<FunctionalType>
142
- ? P
143
- : never]: PropertyInstance<any>
144
- }
145
-
146
- interface ReferencePropertyInstance<T extends FunctionalModel>
147
- extends PropertyInstance<ModelInstance<T> | T | MaybeEmpty<PrimaryKeyType>> {
148
- readonly getReferencedId: (
149
- instanceValues: ReferenceValueType<T>
150
- ) => MaybeEmpty<PrimaryKeyType>
151
- readonly getReferencedModel: () => Model<T>
152
- }
153
-
154
- type ReferenceValueType<T extends FunctionalModel> =
155
- | ModelInstance<T>
156
- | ModelInstanceInputData<T>
157
- | string
158
- | number
159
- | null
160
- | undefined
161
-
162
- type DefaultPropertyValidators = {
163
- readonly required?: boolean
164
- readonly isInteger?: boolean
165
- readonly isNumber?: boolean
166
- readonly isString?: boolean
167
- readonly isArray?: boolean
168
- readonly isBoolean?: boolean
169
- }
170
-
171
- type PropertyConfigContents = {
172
- readonly type?: string
173
- readonly defaultValue?: Arrayable<FunctionalType>
174
- readonly value?: Arrayable<FunctionalType>
175
- readonly choices?: readonly VeryPrimitivesTypes[]
176
- readonly lazyLoadMethod?: (
177
- value: Arrayable<FunctionalType>
178
- ) => MaybeLazy<Arrayable<FunctionalType>>
179
- readonly valueSelector?: (
180
- instanceValue: MaybePromise<Arrayable<FunctionalType>>
181
- ) => Arrayable<FunctionalType>
182
- readonly validators?: readonly PropertyValidatorComponent[]
183
- readonly maxLength?: number
184
- readonly minLength?: number
185
- readonly maxValue?: number
186
- readonly minValue?: number
187
- readonly autoNow?: boolean
188
- readonly fetcher?: (
189
- model: Model<any>,
190
- primaryKey: PrimaryKeyType
191
- ) => Promise<any>
192
- }
193
-
194
- type PropertyConfig =
195
- | (PropertyConfigContents & DefaultPropertyValidators)
196
- | undefined
197
-
198
- type PrimaryKeyPropertyInstanceType =
199
- | PropertyInstance<string>
200
- | PropertyInstance<number>
201
- type PrimaryKeyType = string | number
202
-
203
- type ModelMethods<T extends FunctionalModel> = ValueIsOfType<
204
- T,
205
- ModelMethod | ModelMethodTyped<T>
206
- >
207
- type InstanceMethods<T extends FunctionalModel> = ValueIsOfType<
208
- T,
209
- ModelInstanceMethod | ModelInstanceMethodTyped<T>
210
- >
211
- type ModelDefinition<T extends FunctionalModel> = {
212
- readonly getPrimaryKeyName?: () => string
213
- readonly properties: PropertiesList<T> & {
214
- readonly id?: PrimaryKeyPropertyInstanceType
215
- }
216
- readonly instanceMethods?: InstanceMethods<T>
217
- readonly modelMethods?: ModelMethods<T>
218
- readonly modelValidators?: readonly ModelComponentValidator[]
219
- }
220
-
221
- type Model<T extends FunctionalModel> = {
222
- readonly getName: () => string
223
- readonly getPrimaryKeyName: () => string
224
- readonly getModelDefinition: () => ModelDefinition<T>
225
- readonly getPrimaryKey: (t: ModelInstanceInputData<T>) => PrimaryKeyType
226
- readonly create: (
227
- data: ModelInstanceInputData<T> & { readonly id?: PrimaryKeyType }
228
- ) => ModelInstance<T>
229
- readonly methods: ModelMethodGetters<T>
230
- }
231
-
232
- type ReferenceFunctions = {
233
- readonly [s: string]: () => ReferenceValueType<any>
234
- }
235
-
236
- type PropertyValidators = {
237
- readonly [s: string]: PropertyValidator
238
- }
239
-
240
- type ModelInstance<T extends FunctionalModel> = {
241
- readonly get: PropertyGetters<T> & {
242
- readonly id: () => MaybePromise<PrimaryKeyType>
243
- }
244
- readonly methods: InstanceMethodGetters<T>
245
- readonly references: ReferenceFunctions
246
- readonly toObj: toObj
247
- readonly getPrimaryKeyName: () => string
248
- readonly getPrimaryKey: () => PrimaryKeyType
249
- readonly validators: PropertyValidators
250
- readonly validate: (options?: {}) => Promise<ModelErrors>
251
- readonly getModel: () => Model<T>
252
- }
253
-
254
- type ModelMethodTyped<T extends FunctionalModel> = (
255
- model: Model<T>,
256
- args?: readonly any[]
257
- ) => any
258
- type ModelMethod = ModelMethodTyped<any>
259
- type ModelMethodClient = (...args: readonly any[]) => any
260
- type ModelInstanceMethodTyped<T extends FunctionalModel> = (
261
- instance: ModelInstance<T>,
262
- args?: readonly any[]
263
- ) => any
264
- type ModelInstanceMethod = ModelInstanceMethodTyped<any>
265
- type ModelInstanceMethodClient = (...args: readonly any[]) => any
266
-
267
- type ModelOptions = {
268
- readonly instanceCreatedCallback: Nullable<
269
- Arrayable<(instance: ModelInstance<any>) => void>
270
- >
271
- }
272
-
273
- type OptionalModelOptions =
274
- | {
275
- readonly instanceCreatedCallback?: Nullable<
276
- Arrayable<(instance: ModelInstance<any>) => void>
277
- >
278
- }
279
- | undefined
280
-
281
- export {
282
- MaybeFunction,
283
- Maybe,
284
- MaybePromise,
285
- Nullable,
286
- Arrayable,
287
- MaybeLazy,
288
- JsonAble,
289
- toObj,
290
- ModelInstance,
291
- Model,
292
- PropertyValidatorComponent,
293
- PropertyValidatorComponentSync,
294
- PropertyValidatorComponentAsync,
295
- PropertyValidatorComponentType,
296
- PropertyValidator,
297
- ModelComponentValidator,
298
- PropertyInstance,
299
- PropertyConfig,
300
- FunctionalType,
301
- ValueGetter,
302
- ReferenceValueType,
303
- ModelDefinition,
304
- ModelOptions,
305
- ModelMethod,
306
- OptionalModelOptions,
307
- ReferencePropertyInstance,
308
- PropertyGetters,
309
- PropertyValidators,
310
- PropertyValidatorComponentTypeAdvanced,
311
- ModelInstanceMethod,
312
- ModelInstanceMethodTyped,
313
- FunctionalModel,
314
- ModelInstanceInputData,
315
- ModelMethodTyped,
316
- ModelMethodGetters,
317
- InstanceMethodGetters,
318
- ReferenceFunctions,
319
- ModelErrors,
320
- MaybeEmpty,
321
- PrimaryKeyType,
322
- }
323
- /* eslint-enable no-unused-vars */
package/src/lazy.ts DELETED
@@ -1,24 +0,0 @@
1
- import AsyncLock from 'async-lock'
2
- import { createUuid } from './utils'
3
-
4
- const lazyValue = (method: Function) => {
5
- const key = createUuid()
6
- const lock = new AsyncLock()
7
- /* eslint-disable functional/no-let */
8
- let value: any = undefined
9
- let called = false
10
- return async (...args: readonly any[]) => {
11
- return lock.acquire(key, async () => {
12
- if (!called) {
13
- called = true
14
- value = await method(...args)
15
- // eslint-disable-next-line require-atomic-updates
16
- }
17
-
18
- return value
19
- })
20
- }
21
- /* eslint-enable functional/no-let */
22
- }
23
-
24
- export { lazyValue }
package/src/methods.ts DELETED
@@ -1,30 +0,0 @@
1
- import {
2
- ModelInstanceMethodTyped,
3
- ModelInstance,
4
- FunctionalModel,
5
- Model,
6
- ModelMethodTyped,
7
- } from './interfaces'
8
-
9
- const WrapperInstanceMethod = <T extends FunctionalModel>(
10
- method: (instance: ModelInstance<T>, args?: readonly any[]) => any
11
- ) => {
12
- const r: ModelInstanceMethodTyped<T> = (
13
- instance: ModelInstance<T>,
14
- ...args: readonly any[]
15
- ) => {
16
- return method(instance, ...args)
17
- }
18
- return r
19
- }
20
-
21
- const WrapperModelMethod = <T extends FunctionalModel>(
22
- method: (model: Model<T>, args?: readonly any[]) => any
23
- ) => {
24
- const r: ModelMethodTyped<T> = (model: Model<T>, ...args: readonly any[]) => {
25
- return method(model, ...args)
26
- }
27
- return r
28
- }
29
-
30
- export { WrapperInstanceMethod, WrapperModelMethod }