@kaspernj/api-maker 1.0.2054 → 1.0.2055
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/build/api.js +64 -212
- package/build/api.js.map +1 -1
- package/build/attribute-not-loaded-error.js +2 -25
- package/build/attribute-not-loaded-error.js.map +1 -1
- package/build/base-component.js +3 -26
- package/build/base-component.js.map +1 -1
- package/build/base-error.js +20 -45
- package/build/base-error.js.map +1 -1
- package/build/base-model/attribute.js +14 -21
- package/build/base-model/attribute.js.map +1 -1
- package/build/base-model/column.js +4 -8
- package/build/base-model/column.js.map +1 -1
- package/build/base-model/reflection.js +11 -51
- package/build/base-model/reflection.js.map +1 -1
- package/build/base-model/scope.js +8 -45
- package/build/base-model/scope.js.map +1 -1
- package/build/base-model.js +583 -836
- package/build/base-model.js.map +1 -1
- package/build/bootstrap/attribute-row.js +87 -172
- package/build/bootstrap/attribute-row.js.map +1 -1
- package/build/bootstrap/attribute-rows.js +21 -50
- package/build/bootstrap/attribute-rows.js.map +1 -1
- package/build/bootstrap/card.js +76 -159
- package/build/bootstrap/card.js.map +1 -1
- package/build/bootstrap/checkbox.js +53 -102
- package/build/bootstrap/checkbox.js.map +1 -1
- package/build/bootstrap/checkboxes.js +116 -202
- package/build/bootstrap/checkboxes.js.map +1 -1
- package/build/bootstrap/input.js +80 -131
- package/build/bootstrap/input.js.map +1 -1
- package/build/bootstrap/invalid-feedback.js +18 -46
- package/build/bootstrap/invalid-feedback.js.map +1 -1
- package/build/bootstrap/paginate.js +99 -164
- package/build/bootstrap/paginate.js.map +1 -1
- package/build/bootstrap/radio-buttons.js +43 -80
- package/build/bootstrap/radio-buttons.js.map +1 -1
- package/build/bootstrap/select.js +43 -90
- package/build/bootstrap/select.js.map +1 -1
- package/build/bootstrap/sort-link.js +68 -151
- package/build/bootstrap/sort-link.js.map +1 -1
- package/build/cable-connection-pool.js +43 -65
- package/build/cable-connection-pool.js.map +1 -1
- package/build/cable-subscription-pool.js +104 -161
- package/build/cable-subscription-pool.js.map +1 -1
- package/build/cable-subscription.js +9 -16
- package/build/cable-subscription.js.map +1 -1
- package/build/cache-key-generator.js +27 -36
- package/build/cache-key-generator.js.map +1 -1
- package/build/can-can.js +80 -201
- package/build/can-can.js.map +1 -1
- package/build/channels-consumer.js +5 -10
- package/build/channels-consumer.js.map +1 -1
- package/build/collection-loader.js +35 -53
- package/build/collection-loader.js.map +1 -1
- package/build/collection.js +160 -307
- package/build/collection.js.map +1 -1
- package/build/command-submit-data.d.ts +1 -1
- package/build/command-submit-data.d.ts.map +1 -1
- package/build/command-submit-data.js +29 -38
- package/build/command-submit-data.js.map +1 -1
- package/build/commands-pool.js +139 -215
- package/build/commands-pool.js.map +1 -1
- package/build/compose.js +3 -11
- package/build/compose.js.map +1 -1
- package/build/config.js +20 -67
- package/build/config.js.map +1 -1
- package/build/custom-error.js +4 -29
- package/build/custom-error.js.map +1 -1
- package/build/data-set-to-attributes.js +5 -41
- package/build/data-set-to-attributes.js.map +1 -1
- package/build/deserializer.js +26 -79
- package/build/deserializer.js.map +1 -1
- package/build/destroy-error.js +4 -29
- package/build/destroy-error.js.map +1 -1
- package/build/devise.js +83 -187
- package/build/devise.js.map +1 -1
- package/build/draggable-sort/controller.js +87 -110
- package/build/draggable-sort/controller.js.map +1 -1
- package/build/draggable-sort/index.js +67 -144
- package/build/draggable-sort/index.js.map +1 -1
- package/build/draggable-sort/item.js +131 -197
- package/build/draggable-sort/item.js.map +1 -1
- package/build/error-logger.js +78 -163
- package/build/error-logger.js.map +1 -1
- package/build/error-messages.js +4 -7
- package/build/error-messages.js.map +1 -1
- package/build/event-connection.js +23 -61
- package/build/event-connection.js.map +1 -1
- package/build/event-emitter-listener.js +6 -23
- package/build/event-emitter-listener.js.map +1 -1
- package/build/event-model-class.js +19 -46
- package/build/event-model-class.js.map +1 -1
- package/build/events.js +3 -8
- package/build/events.js.map +1 -1
- package/build/form.js +65 -153
- package/build/form.js.map +1 -1
- package/build/history-expo.js +12 -24
- package/build/history-expo.js.map +1 -1
- package/build/history-react-native.js +14 -26
- package/build/history-react-native.js.map +1 -1
- package/build/history.js +2 -4
- package/build/history.js.map +1 -1
- package/build/index.js +2 -5
- package/build/index.js.map +1 -1
- package/build/inputs/attachment.js +71 -122
- package/build/inputs/attachment.js.map +1 -1
- package/build/inputs/auto-submit.js +15 -54
- package/build/inputs/auto-submit.js.map +1 -1
- package/build/inputs/checkbox.js +77 -166
- package/build/inputs/checkbox.js.map +1 -1
- package/build/inputs/checkboxes.js +75 -158
- package/build/inputs/checkboxes.js.map +1 -1
- package/build/inputs/id-for-component.js +4 -40
- package/build/inputs/id-for-component.js.map +1 -1
- package/build/inputs/input-wrapper.js +7 -26
- package/build/inputs/input-wrapper.js.map +1 -1
- package/build/inputs/input.js +158 -244
- package/build/inputs/input.js.map +1 -1
- package/build/inputs/money.js +123 -185
- package/build/inputs/money.js.map +1 -1
- package/build/inputs/name-for-component.js +4 -40
- package/build/inputs/name-for-component.js.map +1 -1
- package/build/inputs/select.js +68 -122
- package/build/inputs/select.js.map +1 -1
- package/build/instance-of-class-name.js +15 -20
- package/build/instance-of-class-name.js.map +1 -1
- package/build/is-expo.js +8 -10
- package/build/is-expo.js.map +1 -1
- package/build/key-value-store.js +51 -127
- package/build/key-value-store.js.map +1 -1
- package/build/link.js +51 -114
- package/build/link.js.map +1 -1
- package/build/logger.js +19 -25
- package/build/logger.js.map +1 -1
- package/build/merge-styles.js +5 -9
- package/build/merge-styles.js.map +1 -1
- package/build/modal.js +14 -61
- package/build/modal.js.map +1 -1
- package/build/model-class-require.js +8 -43
- package/build/model-class-require.js.map +1 -1
- package/build/model-events.js +24 -33
- package/build/model-events.js.map +1 -1
- package/build/model-name.js +15 -56
- package/build/model-name.js.map +1 -1
- package/build/model-prop-type.js +51 -62
- package/build/model-prop-type.js.map +1 -1
- package/build/model-recipes-loader.js +16 -24
- package/build/model-recipes-loader.js.map +1 -1
- package/build/model-recipes-model-loader.d.ts +1 -1
- package/build/model-recipes-model-loader.js +129 -207
- package/build/model-recipes-model-loader.js.map +1 -1
- package/build/models-response-reader.js +24 -65
- package/build/models-response-reader.js.map +1 -1
- package/build/models.js +5 -10
- package/build/models.js.map +1 -1
- package/build/money-formatter.d.ts +2 -2
- package/build/money-formatter.d.ts.map +1 -1
- package/build/money-formatter.js +45 -55
- package/build/money-formatter.js.map +1 -1
- package/build/not-loaded-error.js +2 -25
- package/build/not-loaded-error.js.map +1 -1
- package/build/params.js +31 -41
- package/build/params.js.map +1 -1
- package/build/preloaded.js +18 -58
- package/build/preloaded.js.map +1 -1
- package/build/resize-observer.js +5 -11
- package/build/resize-observer.js.map +1 -1
- package/build/rest-props-validator.js +4 -6
- package/build/rest-props-validator.js.map +1 -1
- package/build/result.js +10 -14
- package/build/result.js.map +1 -1
- package/build/router/route.js +178 -311
- package/build/router/route.js.map +1 -1
- package/build/router/switch.js +55 -129
- package/build/router/switch.js.map +1 -1
- package/build/router.js +33 -93
- package/build/router.js.map +1 -1
- package/build/routes-native.js +63 -147
- package/build/routes-native.js.map +1 -1
- package/build/routes.js +25 -79
- package/build/routes.js.map +1 -1
- package/build/run-last.js +19 -24
- package/build/run-last.js.map +1 -1
- package/build/serializer.js +28 -33
- package/build/serializer.js.map +1 -1
- package/build/services.js +9 -18
- package/build/services.js.map +1 -1
- package/build/session-status-updater.js +84 -183
- package/build/session-status-updater.js.map +1 -1
- package/build/source-maps-loader.d.ts +37 -0
- package/build/source-maps-loader.d.ts.map +1 -0
- package/build/source-maps-loader.js +102 -224
- package/build/source-maps-loader.js.map +1 -1
- package/build/super-admin/config-reader.d.ts +2 -2
- package/build/super-admin/config-reader.js +41 -82
- package/build/super-admin/config-reader.js.map +1 -1
- package/build/super-admin/edit-page/edit-attribute-checkbox.js +52 -114
- package/build/super-admin/edit-page/edit-attribute-checkbox.js.map +1 -1
- package/build/super-admin/edit-page/edit-attribute-content.js +46 -76
- package/build/super-admin/edit-page/edit-attribute-content.js.map +1 -1
- package/build/super-admin/edit-page/edit-attribute-input.js +56 -118
- package/build/super-admin/edit-page/edit-attribute-input.js.map +1 -1
- package/build/super-admin/edit-page/edit-attribute.js +39 -103
- package/build/super-admin/edit-page/edit-attribute.js.map +1 -1
- package/build/super-admin/edit-page.js +87 -200
- package/build/super-admin/edit-page.js.map +1 -1
- package/build/super-admin/has-edit-config.js +6 -12
- package/build/super-admin/has-edit-config.js.map +1 -1
- package/build/super-admin/index-page.js +16 -43
- package/build/super-admin/index-page.js.map +1 -1
- package/build/super-admin/index.js +86 -209
- package/build/super-admin/index.js.map +1 -1
- package/build/super-admin/layout/header/index.js +90 -151
- package/build/super-admin/layout/header/index.js.map +1 -1
- package/build/super-admin/layout/index.js +69 -152
- package/build/super-admin/layout/index.js.map +1 -1
- package/build/super-admin/layout/menu/index.js +84 -160
- package/build/super-admin/layout/menu/index.js.map +1 -1
- package/build/super-admin/layout/menu/menu-content.js +24 -84
- package/build/super-admin/layout/menu/menu-content.js.map +1 -1
- package/build/super-admin/layout/menu/menu-item.js +51 -101
- package/build/super-admin/layout/menu/menu-item.js.map +1 -1
- package/build/super-admin/layout/no-access.js +18 -44
- package/build/super-admin/layout/no-access.js.map +1 -1
- package/build/super-admin/model-class-table.js +44 -128
- package/build/super-admin/model-class-table.js.map +1 -1
- package/build/super-admin/models.js +5 -41
- package/build/super-admin/models.js.map +1 -1
- package/build/super-admin/show-nav.js +26 -88
- package/build/super-admin/show-nav.js.map +1 -1
- package/build/super-admin/show-page/belongs-to-attribute-row.js +17 -75
- package/build/super-admin/show-page/belongs-to-attribute-row.js.map +1 -1
- package/build/super-admin/show-page/index.js +100 -186
- package/build/super-admin/show-page/index.js.map +1 -1
- package/build/super-admin/show-reflection-actions.js +38 -99
- package/build/super-admin/show-reflection-actions.js.map +1 -1
- package/build/super-admin/show-reflection-link.js +26 -98
- package/build/super-admin/show-reflection-link.js.map +1 -1
- package/build/super-admin/show-reflection-page.js +33 -96
- package/build/super-admin/show-reflection-page.js.map +1 -1
- package/build/table/column-content.js +76 -120
- package/build/table/column-content.js.map +1 -1
- package/build/table/column-identifier.js +6 -10
- package/build/table/column-identifier.js.map +1 -1
- package/build/table/column-visible.js +1 -4
- package/build/table/column-visible.js.map +1 -1
- package/build/table/components/column.js +12 -59
- package/build/table/components/column.js.map +1 -1
- package/build/table/components/flat-list.js +12 -59
- package/build/table/components/flat-list.js.map +1 -1
- package/build/table/components/header.js +14 -61
- package/build/table/components/header.js.map +1 -1
- package/build/table/components/row.js +15 -62
- package/build/table/components/row.js.map +1 -1
- package/build/table/filters/attribute-element.js +33 -61
- package/build/table/filters/attribute-element.js.map +1 -1
- package/build/table/filters/filter-form.js +279 -482
- package/build/table/filters/filter-form.js.map +1 -1
- package/build/table/filters/filter.js +44 -72
- package/build/table/filters/filter.js.map +1 -1
- package/build/table/filters/index.js +94 -138
- package/build/table/filters/index.js.map +1 -1
- package/build/table/filters/load-search-modal.js +63 -211
- package/build/table/filters/load-search-modal.js.map +1 -1
- package/build/table/filters/reflection-element.js +26 -54
- package/build/table/filters/reflection-element.js.map +1 -1
- package/build/table/filters/save-search-modal.js +43 -139
- package/build/table/filters/save-search-modal.js.map +1 -1
- package/build/table/filters/scope-element.js +27 -55
- package/build/table/filters/scope-element.js.map +1 -1
- package/build/table/header-column-content.js +32 -70
- package/build/table/header-column-content.js.map +1 -1
- package/build/table/header-column.js +88 -217
- package/build/table/header-column.js.map +1 -1
- package/build/table/header-select.js +44 -76
- package/build/table/header-select.js.map +1 -1
- package/build/table/model-callback-args.js +4 -40
- package/build/table/model-callback-args.js.map +1 -1
- package/build/table/model-column.js +58 -143
- package/build/table/model-column.js.map +1 -1
- package/build/table/model-row.js +74 -186
- package/build/table/model-row.js.map +1 -1
- package/build/table/select-calculator.js +26 -85
- package/build/table/select-calculator.js.map +1 -1
- package/build/table/settings/column-row.js +65 -185
- package/build/table/settings/column-row.js.map +1 -1
- package/build/table/settings/download-action.js +37 -73
- package/build/table/settings/download-action.js.map +1 -1
- package/build/table/settings/index.js +37 -101
- package/build/table/settings/index.js.map +1 -1
- package/build/table/table-settings.js +184 -322
- package/build/table/table-settings.js.map +1 -1
- package/build/table/table.js +582 -780
- package/build/table/table.js.map +1 -1
- package/build/table/use-sorting.js +15 -34
- package/build/table/use-sorting.js.map +1 -1
- package/build/table/widths.js +31 -37
- package/build/table/widths.js.map +1 -1
- package/build/table/worker-plugins-check-all-checkbox.js +76 -224
- package/build/table/worker-plugins-check-all-checkbox.js.map +1 -1
- package/build/table/worker-plugins-checkbox.js +73 -184
- package/build/table/worker-plugins-checkbox.js.map +1 -1
- package/build/translated-attributes.js +5 -10
- package/build/translated-attributes.js.map +1 -1
- package/build/translated-collections.js +10 -19
- package/build/translated-collections.js.map +1 -1
- package/build/updated-attribute.js +46 -119
- package/build/updated-attribute.js.map +1 -1
- package/build/url-encode.js +5 -11
- package/build/url-encode.js.map +1 -1
- package/build/use-breakpoint.js +42 -94
- package/build/use-breakpoint.js.map +1 -1
- package/build/use-can-can.js +29 -91
- package/build/use-can-can.js.map +1 -1
- package/build/use-collection.js +118 -228
- package/build/use-collection.js.map +1 -1
- package/build/use-created-event.js +26 -43
- package/build/use-created-event.js.map +1 -1
- package/build/use-current-user-context.js +56 -150
- package/build/use-current-user-context.js.map +1 -1
- package/build/use-current-user.js +13 -31
- package/build/use-current-user.js.map +1 -1
- package/build/use-destroyed-event.js +21 -42
- package/build/use-destroyed-event.js.map +1 -1
- package/build/use-event-emitter.js +9 -14
- package/build/use-event-emitter.js.map +1 -1
- package/build/use-event-listener.js +12 -21
- package/build/use-event-listener.js.map +1 -1
- package/build/use-input.js +48 -68
- package/build/use-input.js.map +1 -1
- package/build/use-model-event.js +21 -42
- package/build/use-model-event.js.map +1 -1
- package/build/use-model.js +95 -198
- package/build/use-model.js.map +1 -1
- package/build/use-resize-observer.js +10 -20
- package/build/use-resize-observer.js.map +1 -1
- package/build/use-router.js +64 -106
- package/build/use-router.js.map +1 -1
- package/build/use-screen-layout.js +16 -18
- package/build/use-screen-layout.js.map +1 -1
- package/build/use-styles.js +23 -74
- package/build/use-styles.js.map +1 -1
- package/build/use-updated-event.js +21 -43
- package/build/use-updated-event.js.map +1 -1
- package/build/use-validation-errors.js +11 -17
- package/build/use-validation-errors.js.map +1 -1
- package/build/utils/button.js +85 -135
- package/build/utils/button.js.map +1 -1
- package/build/utils/card.js +30 -105
- package/build/utils/card.js.map +1 -1
- package/build/utils/checkbox.js +50 -111
- package/build/utils/checkbox.js.map +1 -1
- package/build/utils/checkboxes.js +108 -181
- package/build/utils/checkboxes.js.map +1 -1
- package/build/utils/default-style.js +28 -102
- package/build/utils/default-style.js.map +1 -1
- package/build/utils/header.js +7 -34
- package/build/utils/header.js.map +1 -1
- package/build/utils/icon.js +35 -116
- package/build/utils/icon.js.map +1 -1
- package/build/utils/invalid-feedback.js +15 -42
- package/build/utils/invalid-feedback.js.map +1 -1
- package/build/utils/modal.js +24 -107
- package/build/utils/modal.js.map +1 -1
- package/build/utils/text.js +9 -36
- package/build/utils/text.js.map +1 -1
- package/build/validation-error.js +30 -88
- package/build/validation-error.js.map +1 -1
- package/build/validation-errors.js +60 -110
- package/build/validation-errors.js.map +1 -1
- package/build/with-api-maker.js +14 -66
- package/build/with-api-maker.js.map +1 -1
- package/build/with-collection.js +13 -63
- package/build/with-collection.js.map +1 -1
- package/build/with-current-user.js +6 -22
- package/build/with-current-user.js.map +1 -1
- package/build/with-model.js +10 -26
- package/build/with-model.js.map +1 -1
- package/build/with-router.js +7 -34
- package/build/with-router.js.map +1 -1
- package/package.json +1 -1
package/build/base-model.js
CHANGED
|
@@ -1,106 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
-
var ownKeys = function(o) {
|
|
31
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
-
var ar = [];
|
|
33
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
-
return ar;
|
|
35
|
-
};
|
|
36
|
-
return ownKeys(o);
|
|
37
|
-
};
|
|
38
|
-
return function (mod) {
|
|
39
|
-
if (mod && mod.__esModule) return mod;
|
|
40
|
-
var result = {};
|
|
41
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
-
__setModuleDefault(result, mod);
|
|
43
|
-
return result;
|
|
44
|
-
};
|
|
45
|
-
})();
|
|
46
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
47
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
48
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
49
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
50
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
51
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
52
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
56
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
57
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
58
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
59
|
-
function step(op) {
|
|
60
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
61
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
62
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
63
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
64
|
-
switch (op[0]) {
|
|
65
|
-
case 0: case 1: t = op; break;
|
|
66
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
67
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
68
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
69
|
-
default:
|
|
70
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
71
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
72
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
73
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
74
|
-
if (t[2]) _.ops.pop();
|
|
75
|
-
_.trys.pop(); continue;
|
|
76
|
-
}
|
|
77
|
-
op = body.call(thisArg, _);
|
|
78
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
79
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
83
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
84
|
-
};
|
|
85
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
86
|
-
var attribute_1 = __importDefault(require("./base-model/attribute"));
|
|
87
|
-
var attribute_not_loaded_error_1 = __importDefault(require("./attribute-not-loaded-error"));
|
|
88
|
-
var cache_key_generator_1 = __importDefault(require("./cache-key-generator"));
|
|
89
|
-
var collection_js_1 = __importDefault(require("./collection.js"));
|
|
90
|
-
var commands_pool_js_1 = __importDefault(require("./commands-pool.js"));
|
|
91
|
-
var config_js_1 = __importDefault(require("./config.js"));
|
|
92
|
-
var custom_error_js_1 = __importDefault(require("./custom-error.js"));
|
|
93
|
-
var diggerize_1 = require("diggerize");
|
|
94
|
-
var form_data_objectizer_1 = __importDefault(require("form-data-objectizer"));
|
|
95
|
-
var inflection = __importStar(require("inflection"));
|
|
96
|
-
var model_name_1 = __importDefault(require("./model-name"));
|
|
97
|
-
var not_loaded_error_1 = __importDefault(require("./not-loaded-error"));
|
|
98
|
-
var object_to_formdata_1 = __importDefault(require("object-to-formdata"));
|
|
99
|
-
var reflection_1 = __importDefault(require("./base-model/reflection"));
|
|
100
|
-
var scope_1 = __importDefault(require("./base-model/scope"));
|
|
101
|
-
var services_js_1 = __importDefault(require("./services.js"));
|
|
102
|
-
var validation_error_js_1 = __importDefault(require("./validation-error.js"));
|
|
103
|
-
var validation_errors_js_1 = require("./validation-errors.js");
|
|
1
|
+
import Attribute from "./base-model/attribute";
|
|
2
|
+
import AttributeNotLoadedError from "./attribute-not-loaded-error";
|
|
3
|
+
import CacheKeyGenerator from "./cache-key-generator";
|
|
4
|
+
import Collection from "./collection.js";
|
|
5
|
+
import CommandsPool from "./commands-pool.js";
|
|
6
|
+
import Config from "./config.js";
|
|
7
|
+
import CustomError from "./custom-error.js";
|
|
8
|
+
import { digg } from "diggerize";
|
|
9
|
+
import FormDataObjectizer from "form-data-objectizer";
|
|
10
|
+
import * as inflection from "inflection";
|
|
11
|
+
import ModelName from "./model-name";
|
|
12
|
+
import NotLoadedError from "./not-loaded-error";
|
|
13
|
+
import objectToFormData from "object-to-formdata";
|
|
14
|
+
import Reflection from "./base-model/reflection";
|
|
15
|
+
import Scope from "./base-model/scope";
|
|
16
|
+
import Services from "./services.js";
|
|
17
|
+
import ValidationError from "./validation-error.js";
|
|
18
|
+
import { ValidationErrors } from "./validation-errors.js";
|
|
104
19
|
/**
|
|
105
20
|
* @typedef {object} ModelClassDataType
|
|
106
21
|
* @property {import("./base-model/attribute.js").AttributeArgType[]} attributes
|
|
@@ -116,62 +31,47 @@ var validation_errors_js_1 = require("./validation-errors.js");
|
|
|
116
31
|
* @property {boolean} [throwValidationError]
|
|
117
32
|
*/
|
|
118
33
|
function objectToUnderscore(object) {
|
|
119
|
-
|
|
120
|
-
for (
|
|
121
|
-
|
|
34
|
+
const newObject = {};
|
|
35
|
+
for (const key in object) {
|
|
36
|
+
const underscoreKey = inflection.underscore(key);
|
|
122
37
|
newObject[underscoreKey] = object[key];
|
|
123
38
|
}
|
|
124
39
|
return newObject;
|
|
125
40
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if (args === void 0) { args = {}; }
|
|
129
|
-
this._callMemberCommand = function (args, commandArgs) { return commands_pool_js_1.default.addCommand(args, commandArgs); };
|
|
130
|
-
this.changes = {};
|
|
131
|
-
this.newRecord = args.isNewRecord;
|
|
132
|
-
this.relationshipsCache = {};
|
|
133
|
-
this.relationships = {};
|
|
134
|
-
if (args && args.data && args.data.a) {
|
|
135
|
-
this._readModelDataFromArgs(args);
|
|
136
|
-
}
|
|
137
|
-
else if (args.a) {
|
|
138
|
-
this.abilities = args.b || {};
|
|
139
|
-
this.modelData = objectToUnderscore(args.a);
|
|
140
|
-
}
|
|
141
|
-
else if (args) {
|
|
142
|
-
this.abilities = {};
|
|
143
|
-
this.modelData = objectToUnderscore(args);
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
this.abilities = {};
|
|
147
|
-
this.modelData = {};
|
|
148
|
-
}
|
|
149
|
-
}
|
|
41
|
+
export default class BaseModel {
|
|
42
|
+
static apiMakerType = "BaseModel";
|
|
150
43
|
/** @returns {Attribute[]} */
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
for (
|
|
155
|
-
|
|
156
|
-
|
|
44
|
+
static attributes() {
|
|
45
|
+
const attributes = this.modelClassData().attributes;
|
|
46
|
+
const result = [];
|
|
47
|
+
for (const attributeKey in attributes) {
|
|
48
|
+
const attributeData = attributes[attributeKey];
|
|
49
|
+
const attribute = new Attribute(attributeData);
|
|
157
50
|
result.push(attribute);
|
|
158
51
|
}
|
|
159
52
|
return result;
|
|
160
|
-
}
|
|
53
|
+
}
|
|
161
54
|
/** @returns {boolean} */
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
55
|
+
static hasAttribute(attributeName) {
|
|
56
|
+
const attributes = digg(this.modelClassData(), "attributes");
|
|
57
|
+
const lowerCaseAttributeName = inflection.underscore(attributeName);
|
|
165
58
|
if (lowerCaseAttributeName in attributes)
|
|
166
59
|
return true;
|
|
167
60
|
return false;
|
|
168
|
-
}
|
|
61
|
+
}
|
|
169
62
|
/**
|
|
170
63
|
* @interface
|
|
171
64
|
* @returns {ModelClassDataType}
|
|
172
65
|
*/
|
|
173
|
-
|
|
66
|
+
static modelClassData() {
|
|
174
67
|
throw new Error("modelClassData should be overriden by child");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @param {ValidationErrors} validationErrors
|
|
71
|
+
* @returns {CustomEvent}
|
|
72
|
+
*/
|
|
73
|
+
static newCustomEvent = (validationErrors) => {
|
|
74
|
+
return new CustomEvent("validation-errors", { detail: validationErrors });
|
|
175
75
|
};
|
|
176
76
|
/**
|
|
177
77
|
* @param {ValidationErrors} validationErrors
|
|
@@ -179,165 +79,161 @@ var BaseModel = /** @class */ (function () {
|
|
|
179
79
|
* @param {object} [options.form]
|
|
180
80
|
* @param {boolean} [options.throwValidationError]
|
|
181
81
|
*/
|
|
182
|
-
|
|
82
|
+
static sendValidationErrorsEvent(validationErrors, options) {
|
|
183
83
|
if (options && options.form) {
|
|
184
|
-
|
|
185
|
-
options.form.dispatchEvent(
|
|
84
|
+
const event = BaseModel.newCustomEvent(validationErrors);
|
|
85
|
+
options.form.dispatchEvent(event);
|
|
186
86
|
}
|
|
187
|
-
}
|
|
87
|
+
}
|
|
188
88
|
/**
|
|
189
89
|
* @template {typeof BaseModel} T
|
|
190
90
|
* @this {T}
|
|
191
91
|
* @param {number | string} id
|
|
192
92
|
* @returns {Promise<InstanceType<T>>}
|
|
193
93
|
*/
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return [2 /*return*/, model];
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
throw new custom_error_js_1.default("Record not found");
|
|
210
|
-
}
|
|
211
|
-
return [2 /*return*/];
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
};
|
|
94
|
+
static async find(id) {
|
|
95
|
+
/** @type {Record<string, any>} */
|
|
96
|
+
const query = {};
|
|
97
|
+
query[`${this.primaryKey()}_eq`] = id;
|
|
98
|
+
const model = /** @type {InstanceType<T>} */ (await this.ransack(query).first());
|
|
99
|
+
if (model) {
|
|
100
|
+
return model;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
throw new CustomError("Record not found");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
216
106
|
/**
|
|
217
107
|
* @template {typeof BaseModel} T
|
|
218
108
|
* @this {T}
|
|
219
109
|
* @param {Record<string, any>} findOrCreateByArgs
|
|
220
110
|
* @returns {Promise<InstanceType<T>>}
|
|
221
111
|
*/
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
switch (_a.label) {
|
|
228
|
-
case 0: return [4 /*yield*/, services_js_1.default.current().sendRequest("Models::FindOrCreateBy", {
|
|
229
|
-
additional_data: args.additionalData,
|
|
230
|
-
find_or_create_by_args: findOrCreateByArgs,
|
|
231
|
-
resource_name: (0, diggerize_1.digg)(this.modelClassData(), "name")
|
|
232
|
-
})];
|
|
233
|
-
case 1:
|
|
234
|
-
result = _a.sent();
|
|
235
|
-
model = ((0, diggerize_1.digg)(result, "model"));
|
|
236
|
-
return [2 /*return*/, model];
|
|
237
|
-
}
|
|
238
|
-
});
|
|
112
|
+
static async findOrCreateBy(findOrCreateByArgs, args = {}) {
|
|
113
|
+
const result = await Services.current().sendRequest("Models::FindOrCreateBy", {
|
|
114
|
+
additional_data: args.additionalData,
|
|
115
|
+
find_or_create_by_args: findOrCreateByArgs,
|
|
116
|
+
resource_name: digg(this.modelClassData(), "name")
|
|
239
117
|
});
|
|
240
|
-
|
|
118
|
+
const model = /** @type {InstanceType<T>} */ (digg(result, "model"));
|
|
119
|
+
return model;
|
|
120
|
+
}
|
|
241
121
|
/** @returns {ModelName} */
|
|
242
|
-
|
|
243
|
-
return new
|
|
244
|
-
}
|
|
122
|
+
static modelName() {
|
|
123
|
+
return new ModelName({ modelClassData: this.modelClassData() });
|
|
124
|
+
}
|
|
245
125
|
/** @returns {string} */
|
|
246
|
-
|
|
247
|
-
return
|
|
248
|
-
}
|
|
126
|
+
static primaryKey() {
|
|
127
|
+
return digg(this.modelClassData(), "primaryKey");
|
|
128
|
+
}
|
|
249
129
|
/**
|
|
250
130
|
* @template {typeof BaseModel} MC
|
|
251
131
|
* @this {MC}
|
|
252
132
|
* @param {Record<string, any>} [query]
|
|
253
133
|
* @returns {import("./collection.js").default<MC>}
|
|
254
134
|
*/
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
};
|
|
135
|
+
static ransack(query = {}) {
|
|
136
|
+
const ModelClass = /** @type {MC} */ (this);
|
|
137
|
+
return new Collection({ modelClass: ModelClass }, { ransack: query });
|
|
138
|
+
}
|
|
260
139
|
/**
|
|
261
140
|
* @template {typeof BaseModel} MC
|
|
262
141
|
* @this {MC}
|
|
263
142
|
* @param {Record<string, any>} [select]
|
|
264
143
|
* @returns {import("./collection.js").default<MC>}
|
|
265
144
|
*/
|
|
266
|
-
|
|
145
|
+
static select(select) {
|
|
267
146
|
return this.ransack().select(select);
|
|
268
|
-
}
|
|
147
|
+
}
|
|
269
148
|
/** @returns {Reflection[]} */
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
for (
|
|
274
|
-
|
|
275
|
-
reflections.push(new reflection_1.default(relationshipData));
|
|
149
|
+
static ransackableAssociations() {
|
|
150
|
+
const relationships = digg(this.modelClassData(), "ransackable_associations");
|
|
151
|
+
const reflections = [];
|
|
152
|
+
for (const relationshipData of relationships) {
|
|
153
|
+
reflections.push(new Reflection(relationshipData));
|
|
276
154
|
}
|
|
277
155
|
return reflections;
|
|
278
|
-
}
|
|
156
|
+
}
|
|
279
157
|
/** @returns {Attribute[]} */
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
for (
|
|
284
|
-
|
|
285
|
-
result.push(new attribute_1.default(attributeData));
|
|
158
|
+
static ransackableAttributes() {
|
|
159
|
+
const attributes = this.modelClassData().ransackable_attributes;
|
|
160
|
+
const result = [];
|
|
161
|
+
for (const attributeData of attributes) {
|
|
162
|
+
result.push(new Attribute(attributeData));
|
|
286
163
|
}
|
|
287
164
|
return result;
|
|
288
|
-
}
|
|
165
|
+
}
|
|
289
166
|
/** @returns {Scope[]} */
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
for (
|
|
294
|
-
|
|
295
|
-
var scope = new scope_1.default(scopeData);
|
|
167
|
+
static ransackableScopes() {
|
|
168
|
+
const ransackableScopes = digg(this.modelClassData(), "ransackable_scopes");
|
|
169
|
+
const result = [];
|
|
170
|
+
for (const scopeData of ransackableScopes) {
|
|
171
|
+
const scope = new Scope(scopeData);
|
|
296
172
|
result.push(scope);
|
|
297
173
|
}
|
|
298
174
|
return result;
|
|
299
|
-
}
|
|
175
|
+
}
|
|
300
176
|
/** @returns {Reflection[]} */
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
for (
|
|
305
|
-
|
|
306
|
-
var reflection = new reflection_1.default(relationshipData);
|
|
177
|
+
static reflections() {
|
|
178
|
+
const relationships = digg(this.modelClassData(), "relationships");
|
|
179
|
+
const reflections = [];
|
|
180
|
+
for (const relationshipData of relationships) {
|
|
181
|
+
const reflection = new Reflection(relationshipData);
|
|
307
182
|
reflections.push(reflection);
|
|
308
183
|
}
|
|
309
184
|
return reflections;
|
|
310
|
-
}
|
|
185
|
+
}
|
|
311
186
|
/** @returns {Reflection} */
|
|
312
|
-
|
|
313
|
-
|
|
187
|
+
static reflection(name) {
|
|
188
|
+
const foundReflection = this.reflections().find((reflection) => reflection.name() == name);
|
|
314
189
|
if (!foundReflection) {
|
|
315
|
-
throw new Error(
|
|
190
|
+
throw new Error(`No such reflection: ${name} in ${this.reflections().map((reflection) => reflection.name()).join(", ")}`);
|
|
316
191
|
}
|
|
317
192
|
return foundReflection;
|
|
318
|
-
}
|
|
193
|
+
}
|
|
319
194
|
/**
|
|
320
195
|
* @returns {string}
|
|
321
196
|
*/
|
|
322
|
-
|
|
323
|
-
|
|
197
|
+
static _token() {
|
|
198
|
+
const csrfTokenElement = document.querySelector("meta[name='csrf-token']");
|
|
324
199
|
if (csrfTokenElement) {
|
|
325
200
|
return csrfTokenElement.getAttribute("content");
|
|
326
201
|
}
|
|
327
|
-
}
|
|
202
|
+
}
|
|
203
|
+
constructor(args = {}) {
|
|
204
|
+
this.changes = {};
|
|
205
|
+
this.newRecord = args.isNewRecord;
|
|
206
|
+
this.relationshipsCache = {};
|
|
207
|
+
this.relationships = {};
|
|
208
|
+
if (args && args.data && args.data.a) {
|
|
209
|
+
this._readModelDataFromArgs(args);
|
|
210
|
+
}
|
|
211
|
+
else if (args.a) {
|
|
212
|
+
this.abilities = args.b || {};
|
|
213
|
+
this.modelData = objectToUnderscore(args.a);
|
|
214
|
+
}
|
|
215
|
+
else if (args) {
|
|
216
|
+
this.abilities = {};
|
|
217
|
+
this.modelData = objectToUnderscore(args);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
this.abilities = {};
|
|
221
|
+
this.modelData = {};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
328
224
|
/**
|
|
329
225
|
* @param {Record<string, any>} newAttributes
|
|
330
226
|
* @returns {void}
|
|
331
227
|
*/
|
|
332
|
-
|
|
333
|
-
for (
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
228
|
+
assignAttributes(newAttributes) {
|
|
229
|
+
for (const key in newAttributes) {
|
|
230
|
+
const newValue = newAttributes[key];
|
|
231
|
+
const attributeUnderscore = inflection.underscore(key);
|
|
232
|
+
let applyChange = true;
|
|
233
|
+
let deleteChange = false;
|
|
338
234
|
if (this.isAttributeLoaded(key)) {
|
|
339
|
-
|
|
340
|
-
|
|
235
|
+
const oldValue = this.readAttribute(key);
|
|
236
|
+
const originalValue = this.modelData[attributeUnderscore];
|
|
341
237
|
if (newValue == oldValue) {
|
|
342
238
|
applyChange = false;
|
|
343
239
|
}
|
|
@@ -353,86 +249,86 @@ var BaseModel = /** @class */ (function () {
|
|
|
353
249
|
delete this.changes[attributeUnderscore];
|
|
354
250
|
}
|
|
355
251
|
}
|
|
356
|
-
}
|
|
252
|
+
}
|
|
357
253
|
/** @returns {Record<string, any>} */
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
for (
|
|
254
|
+
attributes() {
|
|
255
|
+
const result = {};
|
|
256
|
+
for (const key in this.modelData) {
|
|
361
257
|
result[key] = this.modelData[key];
|
|
362
258
|
}
|
|
363
|
-
for (
|
|
259
|
+
for (const key in this.changes) {
|
|
364
260
|
result[key] = this.changes[key];
|
|
365
261
|
}
|
|
366
262
|
return result;
|
|
367
|
-
}
|
|
263
|
+
}
|
|
368
264
|
/**
|
|
369
265
|
* @param {string} givenAbilityName
|
|
370
266
|
* @returns {boolean}
|
|
371
267
|
*/
|
|
372
|
-
|
|
373
|
-
|
|
268
|
+
can(givenAbilityName) {
|
|
269
|
+
const abilityName = inflection.underscore(givenAbilityName);
|
|
374
270
|
if (!(abilityName in this.abilities)) {
|
|
375
|
-
throw new Error(
|
|
271
|
+
throw new Error(`Ability ${abilityName} hasn't been loaded for ${digg(this.modelClassData(), "name")}`);
|
|
376
272
|
}
|
|
377
273
|
return this.abilities[abilityName];
|
|
378
|
-
}
|
|
274
|
+
}
|
|
379
275
|
/**
|
|
380
276
|
* @template {BaseModel} Self
|
|
381
277
|
* @this {Self}
|
|
382
278
|
* @returns {Self}
|
|
383
279
|
*/
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
clone.abilities =
|
|
388
|
-
clone.modelData =
|
|
389
|
-
clone.relationships =
|
|
390
|
-
clone.relationshipsCache =
|
|
280
|
+
clone() {
|
|
281
|
+
const ModelClass = /** @type {new (...args: any[]) => Self} */ (this.constructor);
|
|
282
|
+
const clone = new ModelClass();
|
|
283
|
+
clone.abilities = { ...this.abilities };
|
|
284
|
+
clone.modelData = { ...this.modelData };
|
|
285
|
+
clone.relationships = { ...this.relationships };
|
|
286
|
+
clone.relationshipsCache = { ...this.relationshipsCache };
|
|
391
287
|
return clone;
|
|
392
|
-
}
|
|
288
|
+
}
|
|
393
289
|
/** @returns {number | string} */
|
|
394
|
-
|
|
290
|
+
cacheKey() {
|
|
395
291
|
if (this.isPersisted()) {
|
|
396
|
-
|
|
292
|
+
const keyParts = [
|
|
397
293
|
this.modelClassData().paramKey,
|
|
398
294
|
this.primaryKey()
|
|
399
295
|
];
|
|
400
296
|
if ("updated_at" in this.modelData) {
|
|
401
297
|
// @ts-expect-error
|
|
402
|
-
|
|
298
|
+
const updatedAt = this.updatedAt();
|
|
403
299
|
if (typeof updatedAt != "object") {
|
|
404
|
-
throw new Error(
|
|
300
|
+
throw new Error(`updatedAt wasn't an object: ${typeof updatedAt}`);
|
|
405
301
|
}
|
|
406
302
|
else if (!("getTime" in updatedAt)) {
|
|
407
|
-
throw new Error(
|
|
303
|
+
throw new Error(`updatedAt didn't support getTime with class: ${updatedAt.constructor && updatedAt.constructor.name}`);
|
|
408
304
|
}
|
|
409
305
|
// @ts-expect-error
|
|
410
|
-
keyParts.push(
|
|
306
|
+
keyParts.push(`updatedAt-${this.updatedAt().getTime()}`);
|
|
411
307
|
}
|
|
412
308
|
return keyParts.join("-");
|
|
413
309
|
}
|
|
414
310
|
else {
|
|
415
311
|
return this.uniqueKey();
|
|
416
312
|
}
|
|
417
|
-
}
|
|
313
|
+
}
|
|
418
314
|
/** @returns {string} */
|
|
419
|
-
|
|
420
|
-
|
|
315
|
+
localCacheKey() {
|
|
316
|
+
const cacheKeyGenerator = new CacheKeyGenerator(this);
|
|
421
317
|
return cacheKeyGenerator.local();
|
|
422
|
-
}
|
|
318
|
+
}
|
|
423
319
|
/** @returns {string} */
|
|
424
|
-
|
|
425
|
-
|
|
320
|
+
fullCacheKey() {
|
|
321
|
+
const cacheKeyGenerator = new CacheKeyGenerator(this);
|
|
426
322
|
return cacheKeyGenerator.cacheKey();
|
|
427
|
-
}
|
|
323
|
+
}
|
|
428
324
|
/**
|
|
429
325
|
* @template {typeof BaseModel} MC
|
|
430
326
|
* @this {MC}
|
|
431
327
|
* @returns {Collection<MC>}
|
|
432
328
|
*/
|
|
433
|
-
|
|
329
|
+
static all() {
|
|
434
330
|
return this.ransack();
|
|
435
|
-
}
|
|
331
|
+
}
|
|
436
332
|
/**
|
|
437
333
|
* @param {Record<string, any>} [attributes]
|
|
438
334
|
* @param {object} [options]
|
|
@@ -441,260 +337,215 @@ var BaseModel = /** @class */ (function () {
|
|
|
441
337
|
* response: object
|
|
442
338
|
* }>}
|
|
443
339
|
*/
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
BaseModel.parseValidationErrors({ error: error_1, model: this, options: options });
|
|
474
|
-
throw error_1;
|
|
475
|
-
case 4:
|
|
476
|
-
if (response.model) {
|
|
477
|
-
this._refreshModelFromResponse(response);
|
|
478
|
-
this.changes = {};
|
|
479
|
-
}
|
|
480
|
-
return [2 /*return*/, { model: this, response: response }];
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
});
|
|
484
|
-
};
|
|
340
|
+
async create(attributes, options) {
|
|
341
|
+
if (attributes)
|
|
342
|
+
this.assignAttributes(attributes);
|
|
343
|
+
const paramKey = this.modelClassData().paramKey;
|
|
344
|
+
const modelData = this.getAttributes();
|
|
345
|
+
const dataToUse = {};
|
|
346
|
+
dataToUse[paramKey] = modelData;
|
|
347
|
+
let response;
|
|
348
|
+
try {
|
|
349
|
+
response = await CommandsPool.addCommand({
|
|
350
|
+
args: {
|
|
351
|
+
save: dataToUse
|
|
352
|
+
},
|
|
353
|
+
command: `${this.modelClassData().collectionName}-create`,
|
|
354
|
+
collectionName: this.modelClassData().collectionName,
|
|
355
|
+
primaryKey: this.primaryKey(),
|
|
356
|
+
type: "create"
|
|
357
|
+
}, {});
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
BaseModel.parseValidationErrors({ error, model: this, options });
|
|
361
|
+
throw error;
|
|
362
|
+
}
|
|
363
|
+
if (response.model) {
|
|
364
|
+
this._refreshModelFromResponse(response);
|
|
365
|
+
this.changes = {};
|
|
366
|
+
}
|
|
367
|
+
return { model: this, response };
|
|
368
|
+
}
|
|
485
369
|
/**
|
|
486
370
|
* @param {FormData | Record<string, any>} rawData
|
|
487
371
|
* @param {object} [options]
|
|
488
372
|
*/
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
error_2 = _a.sent();
|
|
514
|
-
BaseModel.parseValidationErrors({ error: error_2, model: this, options: options });
|
|
515
|
-
throw error_2;
|
|
516
|
-
case 4:
|
|
517
|
-
if (response.model) {
|
|
518
|
-
this._refreshModelDataFromResponse(response);
|
|
519
|
-
this.changes = {};
|
|
520
|
-
}
|
|
521
|
-
return [2 /*return*/, { model: this, response: response }];
|
|
522
|
-
}
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
};
|
|
373
|
+
async createRaw(rawData, options = {}) {
|
|
374
|
+
const objectData = BaseModel._objectDataFromGivenRawData(rawData, options);
|
|
375
|
+
let response;
|
|
376
|
+
try {
|
|
377
|
+
response = await CommandsPool.addCommand({
|
|
378
|
+
args: {
|
|
379
|
+
save: objectData
|
|
380
|
+
},
|
|
381
|
+
command: `${this.modelClassData().collectionName}-create`,
|
|
382
|
+
collectionName: this.modelClassData().collectionName,
|
|
383
|
+
primaryKey: this.primaryKey(),
|
|
384
|
+
type: "create"
|
|
385
|
+
}, {});
|
|
386
|
+
}
|
|
387
|
+
catch (error) {
|
|
388
|
+
BaseModel.parseValidationErrors({ error, model: this, options });
|
|
389
|
+
throw error;
|
|
390
|
+
}
|
|
391
|
+
if (response.model) {
|
|
392
|
+
this._refreshModelDataFromResponse(response);
|
|
393
|
+
this.changes = {};
|
|
394
|
+
}
|
|
395
|
+
return { model: this, response };
|
|
396
|
+
}
|
|
526
397
|
/** @returns {Promise<{model: BaseModel, response: object}>} */
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
abilitiesParams[(0, diggerize_1.digg)(this.modelClassData(), "name")] = abilitiesToLoad;
|
|
575
|
-
return [4 /*yield*/, this.modelClass()
|
|
576
|
-
.ransack(ransackParams)
|
|
577
|
-
.abilities(abilitiesParams)
|
|
578
|
-
.first()];
|
|
579
|
-
case 1:
|
|
580
|
-
anotherModel = _a.sent();
|
|
581
|
-
if (!anotherModel) {
|
|
582
|
-
throw new Error("Could not look up the same model ".concat(this.primaryKey(), " with abilities: ").concat(abilitiesToLoad.join(", ")));
|
|
583
|
-
}
|
|
584
|
-
newAbilities = anotherModel.abilities;
|
|
585
|
-
for (newAbility in newAbilities) {
|
|
586
|
-
this.abilities[newAbility] = newAbilities[newAbility];
|
|
587
|
-
}
|
|
588
|
-
_a.label = 2;
|
|
589
|
-
case 2: return [2 /*return*/];
|
|
590
|
-
}
|
|
591
|
-
});
|
|
592
|
-
});
|
|
593
|
-
};
|
|
398
|
+
async destroy() {
|
|
399
|
+
const response = await CommandsPool.addCommand({
|
|
400
|
+
args: { query_params: this.collection && this.collection.params() },
|
|
401
|
+
command: `${this.modelClassData().collectionName}-destroy`,
|
|
402
|
+
collectionName: this.modelClassData().collectionName,
|
|
403
|
+
primaryKey: this.primaryKey(),
|
|
404
|
+
type: "destroy"
|
|
405
|
+
}, {});
|
|
406
|
+
if (response.success) {
|
|
407
|
+
if (response.model) {
|
|
408
|
+
this._refreshModelDataFromResponse(response);
|
|
409
|
+
this.changes = {};
|
|
410
|
+
}
|
|
411
|
+
return { model: this, response };
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
this.handleResponseError(response);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
async ensureAbilities(listOfAbilities) {
|
|
418
|
+
// Populate an array with a list of abilities currently not loaded
|
|
419
|
+
const abilitiesToLoad = [];
|
|
420
|
+
for (const abilityInList of listOfAbilities) {
|
|
421
|
+
if (!(abilityInList in this.abilities)) {
|
|
422
|
+
abilitiesToLoad.push(abilityInList);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
// Load the missing abilities if any
|
|
426
|
+
if (abilitiesToLoad.length > 0) {
|
|
427
|
+
const primaryKeyName = this.modelClass().primaryKey();
|
|
428
|
+
const ransackParams = {};
|
|
429
|
+
ransackParams[`${primaryKeyName}_eq`] = this.primaryKey();
|
|
430
|
+
const abilitiesParams = {};
|
|
431
|
+
abilitiesParams[digg(this.modelClassData(), "name")] = abilitiesToLoad;
|
|
432
|
+
const anotherModel = await this.modelClass()
|
|
433
|
+
.ransack(ransackParams)
|
|
434
|
+
.abilities(abilitiesParams)
|
|
435
|
+
.first();
|
|
436
|
+
if (!anotherModel) {
|
|
437
|
+
throw new Error(`Could not look up the same model ${this.primaryKey()} with abilities: ${abilitiesToLoad.join(", ")}`);
|
|
438
|
+
}
|
|
439
|
+
const newAbilities = anotherModel.abilities;
|
|
440
|
+
for (const newAbility in newAbilities) {
|
|
441
|
+
this.abilities[newAbility] = newAbilities[newAbility];
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
594
445
|
/**
|
|
595
446
|
* @returns {Record<string, any>}
|
|
596
447
|
*/
|
|
597
|
-
|
|
598
|
-
|
|
448
|
+
getAttributes() { return Object.assign(this.modelData, this.changes); }
|
|
449
|
+
asd;
|
|
450
|
+
handleResponseError(response) {
|
|
599
451
|
// @ts-expect-error
|
|
600
|
-
BaseModel.parseValidationErrors({ model: this, response
|
|
601
|
-
throw new
|
|
602
|
-
}
|
|
452
|
+
BaseModel.parseValidationErrors({ model: this, response });
|
|
453
|
+
throw new CustomError("Response wasn't successful", { model: this, response });
|
|
454
|
+
}
|
|
603
455
|
/**
|
|
604
456
|
* @returns {number | string}
|
|
605
457
|
*/
|
|
606
|
-
|
|
458
|
+
identifierKey() {
|
|
607
459
|
if (!this._identifierKey)
|
|
608
460
|
this._identifierKey = this.isPersisted() ? this.primaryKey() : this.uniqueKey();
|
|
609
461
|
return this._identifierKey;
|
|
610
|
-
}
|
|
462
|
+
}
|
|
611
463
|
/**
|
|
612
464
|
* @returns {boolean}
|
|
613
465
|
*/
|
|
614
|
-
|
|
466
|
+
isAssociationLoaded(associationName) { return this.isAssociationLoadedUnderscore(inflection.underscore(associationName)); }
|
|
615
467
|
/**
|
|
616
468
|
* @returns {boolean}
|
|
617
469
|
*/
|
|
618
|
-
|
|
470
|
+
isAssociationLoadedUnderscore(associationNameUnderscore) {
|
|
619
471
|
if (associationNameUnderscore in this.relationshipsCache)
|
|
620
472
|
return true;
|
|
621
473
|
return false;
|
|
622
|
-
}
|
|
474
|
+
}
|
|
623
475
|
/**
|
|
624
476
|
* @returns {boolean}
|
|
625
477
|
*/
|
|
626
|
-
|
|
478
|
+
isAssociationPresent(associationName) {
|
|
627
479
|
if (this.isAssociationLoaded(associationName))
|
|
628
480
|
return true;
|
|
629
481
|
if (associationName in this.relationships)
|
|
630
482
|
return true;
|
|
631
483
|
return false;
|
|
632
|
-
}
|
|
484
|
+
}
|
|
633
485
|
/**
|
|
634
486
|
* @param {object} args
|
|
635
487
|
* @param {any} args.error
|
|
636
488
|
* @param {BaseModel} [args.model]
|
|
637
489
|
* @param {ParseValidationErrorsOptions} args.options
|
|
638
490
|
*/
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
if (!(error instanceof validation_error_js_1.default))
|
|
491
|
+
static parseValidationErrors({ error, model, options }) {
|
|
492
|
+
if (!(error instanceof ValidationError))
|
|
642
493
|
return;
|
|
643
494
|
if (!error.args.response.validation_errors)
|
|
644
495
|
return;
|
|
645
|
-
|
|
646
|
-
model
|
|
647
|
-
validationErrors:
|
|
496
|
+
const validationErrors = new ValidationErrors({
|
|
497
|
+
model,
|
|
498
|
+
validationErrors: digg(error, "args", "response", "validation_errors")
|
|
648
499
|
});
|
|
649
500
|
BaseModel.sendValidationErrorsEvent(validationErrors, options);
|
|
650
501
|
if (!options || options.throwValidationError != false) {
|
|
651
502
|
throw error;
|
|
652
503
|
}
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
|
|
504
|
+
}
|
|
505
|
+
static humanAttributeName(attributeName) {
|
|
506
|
+
const keyName = digg(this.modelClassData(), "i18nKey");
|
|
656
507
|
// @ts-expect-error
|
|
657
|
-
|
|
508
|
+
const i18n = Config.getI18n();
|
|
658
509
|
if (i18n)
|
|
659
|
-
return i18n.t(
|
|
510
|
+
return i18n.t(`activerecord.attributes.${keyName}.${BaseModel.snakeCase(attributeName)}`, { defaultValue: attributeName });
|
|
660
511
|
return inflection.humanize(attributeName);
|
|
661
|
-
}
|
|
512
|
+
}
|
|
662
513
|
/**
|
|
663
514
|
* @param {string} attributeName
|
|
664
515
|
* @returns {boolean}
|
|
665
516
|
*/
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
517
|
+
isAttributeChanged(attributeName) {
|
|
518
|
+
const attributeNameUnderscore = inflection.underscore(attributeName);
|
|
519
|
+
const attributeData = this.modelClassData().attributes.find((attribute) => digg(attribute, "name") == attributeNameUnderscore);
|
|
669
520
|
if (!attributeData) {
|
|
670
|
-
|
|
671
|
-
throw new Error(
|
|
521
|
+
const attributeNames = this.modelClassData().attributes.map((attribute) => digg(attribute, "name"));
|
|
522
|
+
throw new Error(`Couldn't find an attribute by that name: "${attributeName}" in: ${attributeNames.join(", ")}`);
|
|
672
523
|
}
|
|
673
524
|
if (!(attributeNameUnderscore in this.changes))
|
|
674
525
|
return false;
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
526
|
+
const oldValue = this.modelData[attributeNameUnderscore];
|
|
527
|
+
const newValue = this.changes[attributeNameUnderscore];
|
|
528
|
+
const changedMethod = this[`_is${inflection.camelize(attributeData.type, true)}Changed`];
|
|
678
529
|
if (!changedMethod)
|
|
679
|
-
throw new Error(
|
|
530
|
+
throw new Error(`Don't know how to handle type: ${attributeData.type}`);
|
|
680
531
|
return changedMethod(oldValue, newValue);
|
|
681
|
-
}
|
|
532
|
+
}
|
|
682
533
|
/**
|
|
683
534
|
* @returns {boolean}
|
|
684
535
|
*/
|
|
685
|
-
|
|
686
|
-
|
|
536
|
+
isChanged() {
|
|
537
|
+
const keys = Object.keys(this.changes);
|
|
687
538
|
if (keys.length > 0) {
|
|
688
539
|
return true;
|
|
689
540
|
}
|
|
690
541
|
else {
|
|
691
542
|
return false;
|
|
692
543
|
}
|
|
693
|
-
}
|
|
544
|
+
}
|
|
694
545
|
/**
|
|
695
546
|
* @returns {boolean}
|
|
696
547
|
*/
|
|
697
|
-
|
|
548
|
+
isNewRecord() {
|
|
698
549
|
if (this.newRecord !== undefined) {
|
|
699
550
|
return this.newRecord;
|
|
700
551
|
}
|
|
@@ -704,133 +555,121 @@ var BaseModel = /** @class */ (function () {
|
|
|
704
555
|
else {
|
|
705
556
|
return true;
|
|
706
557
|
}
|
|
707
|
-
}
|
|
558
|
+
}
|
|
708
559
|
/**
|
|
709
560
|
* @returns {boolean}
|
|
710
561
|
*/
|
|
711
|
-
|
|
562
|
+
isPersisted() { return !this.isNewRecord(); }
|
|
712
563
|
/**
|
|
713
564
|
* @param {string} string
|
|
714
565
|
* @returns {string}
|
|
715
566
|
*/
|
|
716
|
-
|
|
567
|
+
static snakeCase(string) { return inflection.underscore(string); }
|
|
717
568
|
/**
|
|
718
569
|
* @param {string} attributeName
|
|
719
570
|
* @returns {boolean}
|
|
720
571
|
*/
|
|
721
|
-
|
|
572
|
+
savedChangeToAttribute(attributeName) {
|
|
722
573
|
if (!this.previousModelData)
|
|
723
574
|
return false;
|
|
724
|
-
|
|
725
|
-
|
|
575
|
+
const attributeNameUnderscore = inflection.underscore(attributeName);
|
|
576
|
+
const attributeData = this.modelClassData().attributes.find((attribute) => attribute.name == attributeNameUnderscore);
|
|
726
577
|
if (!attributeData) {
|
|
727
|
-
|
|
728
|
-
throw new Error(
|
|
578
|
+
const attributeNames = this.modelClassData().attributes.map((attribute) => attribute.name);
|
|
579
|
+
throw new Error(`Couldn't find an attribute by that name: "${attributeName}" in: ${attributeNames.join(", ")}`);
|
|
729
580
|
}
|
|
730
581
|
if (!(attributeNameUnderscore in this.previousModelData))
|
|
731
582
|
return true;
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
583
|
+
const oldValue = this.previousModelData[attributeNameUnderscore];
|
|
584
|
+
const newValue = this.modelData[attributeNameUnderscore];
|
|
585
|
+
const changedMethodName = `_is${inflection.camelize(attributeData.type)}Changed`;
|
|
586
|
+
const changedMethod = this[changedMethodName];
|
|
736
587
|
if (!changedMethod)
|
|
737
|
-
throw new Error(
|
|
588
|
+
throw new Error(`Don't know how to handle type: ${attributeData.type}`);
|
|
738
589
|
return changedMethod(oldValue, newValue);
|
|
739
|
-
}
|
|
590
|
+
}
|
|
740
591
|
/**
|
|
741
592
|
* @param {BaseModel} model
|
|
742
593
|
* @returns {void}
|
|
743
594
|
*/
|
|
744
|
-
|
|
595
|
+
setNewModel(model) {
|
|
745
596
|
this.setNewModelData(model);
|
|
746
|
-
for (
|
|
597
|
+
for (const relationshipName in model.relationships) {
|
|
747
598
|
this.relationships[relationshipName] = model.relationships[relationshipName];
|
|
748
599
|
}
|
|
749
|
-
for (
|
|
600
|
+
for (const relationshipCacheName in model.relationshipsCache) {
|
|
750
601
|
this.relationshipsCache[relationshipCacheName] = model.relationshipsCache[name];
|
|
751
602
|
}
|
|
752
|
-
}
|
|
753
|
-
|
|
603
|
+
}
|
|
604
|
+
setNewModelData(model) {
|
|
754
605
|
if (!("modelData" in model))
|
|
755
|
-
throw new Error(
|
|
756
|
-
this.previousModelData = Object.assign({},
|
|
757
|
-
for (
|
|
606
|
+
throw new Error(`No modelData in model: ${JSON.stringify(model)}`);
|
|
607
|
+
this.previousModelData = Object.assign({}, digg(this, "modelData"));
|
|
608
|
+
for (const attributeName in model.modelData) {
|
|
758
609
|
this.modelData[attributeName] = model.modelData[attributeName];
|
|
759
610
|
}
|
|
760
|
-
}
|
|
761
|
-
|
|
611
|
+
}
|
|
612
|
+
_isDateChanged(oldValue, newValue) {
|
|
762
613
|
if (Date.parse(oldValue) != Date.parse(newValue))
|
|
763
614
|
return true;
|
|
764
|
-
}
|
|
765
|
-
|
|
615
|
+
}
|
|
616
|
+
_isIntegerChanged(oldValue, newValue) {
|
|
766
617
|
if (parseInt(oldValue, 10) != parseInt(newValue, 10))
|
|
767
618
|
return true;
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
619
|
+
}
|
|
620
|
+
_isStringChanged(oldValue, newValue) {
|
|
621
|
+
const oldConvertedValue = `${oldValue}`;
|
|
622
|
+
const newConvertedValue = `${newValue}`;
|
|
772
623
|
if (oldConvertedValue != newConvertedValue)
|
|
773
624
|
return true;
|
|
774
|
-
}
|
|
625
|
+
}
|
|
775
626
|
/** @returns {ModelClassDataType} */
|
|
776
|
-
|
|
627
|
+
modelClassData() { return this.modelClass().modelClassData(); }
|
|
777
628
|
/**
|
|
778
629
|
* @returns {Promise<void>}
|
|
779
630
|
*/
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
}
|
|
801
|
-
return [4 /*yield*/, query.first()];
|
|
802
|
-
case 1:
|
|
803
|
-
model = _a.sent();
|
|
804
|
-
this.setNewModel(model);
|
|
805
|
-
this.changes = {};
|
|
806
|
-
return [2 /*return*/];
|
|
807
|
-
}
|
|
808
|
-
});
|
|
809
|
-
});
|
|
810
|
-
};
|
|
631
|
+
async reload() {
|
|
632
|
+
const params = this.collection && this.collection.params();
|
|
633
|
+
const ransackParams = {};
|
|
634
|
+
ransackParams[`${this.modelClass().primaryKey()}_eq`] = this.primaryKey();
|
|
635
|
+
let query = this.modelClass().ransack(ransackParams);
|
|
636
|
+
if (params) {
|
|
637
|
+
if (params.preload) {
|
|
638
|
+
query.queryArgs.preload = params.preload;
|
|
639
|
+
}
|
|
640
|
+
if (params.select) {
|
|
641
|
+
query.queryArgs.select = params.select;
|
|
642
|
+
}
|
|
643
|
+
if (params.select_columns) {
|
|
644
|
+
query.queryArgs.selectColumns = params.select_columns;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
const model = await query.first();
|
|
648
|
+
this.setNewModel(model);
|
|
649
|
+
this.changes = {};
|
|
650
|
+
}
|
|
811
651
|
/**
|
|
812
652
|
* @returns {Promise<{model: BaseModel, response?: object}>}
|
|
813
653
|
*/
|
|
814
|
-
|
|
654
|
+
save() {
|
|
815
655
|
if (this.isNewRecord()) {
|
|
816
656
|
return this.create();
|
|
817
657
|
}
|
|
818
658
|
else {
|
|
819
659
|
return this.update();
|
|
820
660
|
}
|
|
821
|
-
}
|
|
661
|
+
}
|
|
822
662
|
/**
|
|
823
663
|
* @returns {Promise<{model: BaseModel, response: object}>}
|
|
824
664
|
*/
|
|
825
|
-
|
|
826
|
-
if (options === void 0) { options = {}; }
|
|
665
|
+
saveRaw(rawData, options = {}) {
|
|
827
666
|
if (this.isNewRecord()) {
|
|
828
667
|
return this.createRaw(rawData, options);
|
|
829
668
|
}
|
|
830
669
|
else {
|
|
831
670
|
return this.updateRaw(rawData, options);
|
|
832
671
|
}
|
|
833
|
-
}
|
|
672
|
+
}
|
|
834
673
|
/**
|
|
835
674
|
* @param {Record<string, any>} [newAttributes]
|
|
836
675
|
* @param {ParseValidationErrorsOptions} [options]
|
|
@@ -839,241 +678,195 @@ var BaseModel = /** @class */ (function () {
|
|
|
839
678
|
* response?: object
|
|
840
679
|
* }>}
|
|
841
680
|
*/
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
}
|
|
884
|
-
return [2 /*return*/, { response: response, model: this }];
|
|
885
|
-
}
|
|
886
|
-
else {
|
|
887
|
-
this.handleResponseError(response);
|
|
888
|
-
}
|
|
889
|
-
return [2 /*return*/];
|
|
890
|
-
}
|
|
891
|
-
});
|
|
892
|
-
});
|
|
893
|
-
};
|
|
894
|
-
BaseModel.prototype._refreshModelFromResponse = function (response) {
|
|
895
|
-
var newModel = (0, diggerize_1.digg)(response, "model");
|
|
681
|
+
async update(newAttributes, options) {
|
|
682
|
+
if (newAttributes) {
|
|
683
|
+
this.assignAttributes(newAttributes);
|
|
684
|
+
}
|
|
685
|
+
if (Object.keys(this.changes).length == 0) {
|
|
686
|
+
return { model: this };
|
|
687
|
+
}
|
|
688
|
+
const paramKey = this.modelClassData().paramKey;
|
|
689
|
+
const modelData = this.changes;
|
|
690
|
+
const dataToUse = {};
|
|
691
|
+
dataToUse[paramKey] = modelData;
|
|
692
|
+
let response;
|
|
693
|
+
try {
|
|
694
|
+
response = await CommandsPool.addCommand({
|
|
695
|
+
args: {
|
|
696
|
+
query_params: this.collection && this.collection.params(),
|
|
697
|
+
save: dataToUse
|
|
698
|
+
},
|
|
699
|
+
command: `${this.modelClassData().collectionName}-update`,
|
|
700
|
+
collectionName: this.modelClassData().collectionName,
|
|
701
|
+
primaryKey: this.primaryKey(),
|
|
702
|
+
type: "update"
|
|
703
|
+
}, {});
|
|
704
|
+
}
|
|
705
|
+
catch (error) {
|
|
706
|
+
BaseModel.parseValidationErrors({ error, model: this, options });
|
|
707
|
+
throw error;
|
|
708
|
+
}
|
|
709
|
+
if (response.success) {
|
|
710
|
+
if (response.model) {
|
|
711
|
+
this._refreshModelFromResponse(response);
|
|
712
|
+
this.changes = {};
|
|
713
|
+
}
|
|
714
|
+
return { response, model: this };
|
|
715
|
+
}
|
|
716
|
+
else {
|
|
717
|
+
this.handleResponseError(response);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
_refreshModelFromResponse(response) {
|
|
721
|
+
let newModel = digg(response, "model");
|
|
896
722
|
if (Array.isArray(newModel))
|
|
897
723
|
newModel = newModel[0];
|
|
898
724
|
this.setNewModel(newModel);
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
|
|
725
|
+
}
|
|
726
|
+
_refreshModelDataFromResponse(response) {
|
|
727
|
+
let newModel = digg(response, "model");
|
|
902
728
|
if (Array.isArray(newModel))
|
|
903
729
|
newModel = newModel[0];
|
|
904
730
|
this.setNewModelData(newModel);
|
|
905
|
-
}
|
|
731
|
+
}
|
|
906
732
|
/**
|
|
907
733
|
* @param {FormData | Record<string, any>} rawData
|
|
908
734
|
* @param {object} options
|
|
909
735
|
* @returns {Record<string, any>}
|
|
910
736
|
*/
|
|
911
|
-
|
|
737
|
+
static _objectDataFromGivenRawData(rawData, options) {
|
|
912
738
|
if (rawData instanceof FormData || rawData.nodeName == "FORM") {
|
|
913
|
-
|
|
914
|
-
return
|
|
739
|
+
const formData = FormDataObjectizer.formDataFromObject(rawData, options);
|
|
740
|
+
return FormDataObjectizer.toObject(formData);
|
|
915
741
|
}
|
|
916
742
|
return rawData;
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
BaseModel.parseValidationErrors({ error: error_4, model: this, options: options });
|
|
946
|
-
throw error_4;
|
|
947
|
-
case 4:
|
|
948
|
-
if (response.model) {
|
|
949
|
-
this._refreshModelFromResponse(response);
|
|
950
|
-
this.changes = {};
|
|
951
|
-
}
|
|
952
|
-
return [2 /*return*/, { response: response, model: this }];
|
|
953
|
-
}
|
|
954
|
-
});
|
|
955
|
-
});
|
|
956
|
-
};
|
|
957
|
-
BaseModel.prototype.isValid = function () {
|
|
743
|
+
}
|
|
744
|
+
async updateRaw(rawData, options = {}) {
|
|
745
|
+
const objectData = BaseModel._objectDataFromGivenRawData(rawData, options);
|
|
746
|
+
let response;
|
|
747
|
+
try {
|
|
748
|
+
response = await CommandsPool.addCommand({
|
|
749
|
+
args: {
|
|
750
|
+
query_params: this.collection && this.collection.params(),
|
|
751
|
+
save: objectData,
|
|
752
|
+
simple_model_errors: options?.simpleModelErrors
|
|
753
|
+
},
|
|
754
|
+
command: `${this.modelClassData().collectionName}-update`,
|
|
755
|
+
collectionName: this.modelClassData().collectionName,
|
|
756
|
+
primaryKey: this.primaryKey(),
|
|
757
|
+
type: "update"
|
|
758
|
+
}, {});
|
|
759
|
+
}
|
|
760
|
+
catch (error) {
|
|
761
|
+
BaseModel.parseValidationErrors({ error, model: this, options });
|
|
762
|
+
throw error;
|
|
763
|
+
}
|
|
764
|
+
if (response.model) {
|
|
765
|
+
this._refreshModelFromResponse(response);
|
|
766
|
+
this.changes = {};
|
|
767
|
+
}
|
|
768
|
+
return { response, model: this };
|
|
769
|
+
}
|
|
770
|
+
isValid() {
|
|
958
771
|
throw new Error("Not implemented yet");
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
primaryKey: this.primaryKey(),
|
|
977
|
-
type: "valid"
|
|
978
|
-
}, {})];
|
|
979
|
-
case 1:
|
|
980
|
-
response = _a.sent();
|
|
981
|
-
return [2 /*return*/, { valid: response.valid, errors: response.errors }];
|
|
982
|
-
}
|
|
983
|
-
});
|
|
984
|
-
});
|
|
985
|
-
};
|
|
772
|
+
}
|
|
773
|
+
async isValidOnServer() {
|
|
774
|
+
const modelData = this.getAttributes();
|
|
775
|
+
const paramKey = this.modelClassData().paramKey;
|
|
776
|
+
const dataToUse = {};
|
|
777
|
+
dataToUse[paramKey] = modelData;
|
|
778
|
+
const response = await CommandsPool.addCommand({
|
|
779
|
+
args: {
|
|
780
|
+
save: dataToUse
|
|
781
|
+
},
|
|
782
|
+
command: `${this.modelClassData().collectionName}-valid`,
|
|
783
|
+
collectionName: this.modelClassData().collectionName,
|
|
784
|
+
primaryKey: this.primaryKey(),
|
|
785
|
+
type: "valid"
|
|
786
|
+
}, {});
|
|
787
|
+
return { valid: response.valid, errors: response.errors };
|
|
788
|
+
}
|
|
986
789
|
/**
|
|
987
790
|
* @template {BaseModel} Self
|
|
988
791
|
* @this {Self}
|
|
989
792
|
* @returns {typeof BaseModel & (new (...args: any[]) => Self)}
|
|
990
793
|
*/
|
|
991
|
-
|
|
794
|
+
modelClass() {
|
|
992
795
|
return /** @type {any} */ (this.constructor);
|
|
993
|
-
}
|
|
994
|
-
|
|
796
|
+
}
|
|
797
|
+
preloadRelationship(relationshipName, model) {
|
|
995
798
|
this.relationshipsCache[BaseModel.snakeCase(relationshipName)] = model;
|
|
996
799
|
this.relationships[BaseModel.snakeCase(relationshipName)] = model;
|
|
997
|
-
}
|
|
800
|
+
}
|
|
998
801
|
/**
|
|
999
802
|
* @returns {void}
|
|
1000
803
|
*/
|
|
1001
|
-
|
|
804
|
+
markForDestruction() {
|
|
1002
805
|
this._markedForDestruction = true;
|
|
1003
|
-
}
|
|
806
|
+
}
|
|
1004
807
|
/**
|
|
1005
808
|
* @returns {boolean}
|
|
1006
809
|
*/
|
|
1007
|
-
|
|
810
|
+
markedForDestruction() { return this._markedForDestruction || false; }
|
|
1008
811
|
/**
|
|
1009
812
|
* @returns {number}
|
|
1010
813
|
*/
|
|
1011
|
-
|
|
814
|
+
uniqueKey() {
|
|
1012
815
|
if (!this.uniqueKeyValue) {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
816
|
+
const min = 5000000000000000;
|
|
817
|
+
const max = 9007199254740991;
|
|
818
|
+
const randomBetween = Math.floor(Math.random() * (max - min + 1) + min);
|
|
1016
819
|
this.uniqueKeyValue = randomBetween;
|
|
1017
820
|
}
|
|
1018
821
|
return this.uniqueKeyValue;
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
return
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
if (form)
|
|
1042
|
-
BaseModel.parseValidationErrors({ error: error_5, options: { form: form } });
|
|
1043
|
-
throw error_5;
|
|
1044
|
-
case 4: return [2 /*return*/];
|
|
1045
|
-
}
|
|
1046
|
-
});
|
|
1047
|
-
});
|
|
1048
|
-
};
|
|
1049
|
-
BaseModel._postDataFromArgs = function (args) {
|
|
1050
|
-
var postData;
|
|
822
|
+
}
|
|
823
|
+
static async _callCollectionCommand(args, commandArgs) {
|
|
824
|
+
const formOrDataObject = args.args;
|
|
825
|
+
try {
|
|
826
|
+
return await CommandsPool.addCommand(args, commandArgs);
|
|
827
|
+
}
|
|
828
|
+
catch (error) {
|
|
829
|
+
let form;
|
|
830
|
+
if (commandArgs.form) {
|
|
831
|
+
form = commandArgs.form;
|
|
832
|
+
}
|
|
833
|
+
else if (formOrDataObject?.nodeName == "FORM") {
|
|
834
|
+
form = formOrDataObject;
|
|
835
|
+
}
|
|
836
|
+
if (form)
|
|
837
|
+
BaseModel.parseValidationErrors({ error, options: { form } });
|
|
838
|
+
throw error;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
_callMemberCommand = (args, commandArgs) => CommandsPool.addCommand(args, commandArgs);
|
|
842
|
+
static _postDataFromArgs(args) {
|
|
843
|
+
let postData;
|
|
1051
844
|
if (args) {
|
|
1052
845
|
if (args instanceof FormData) {
|
|
1053
846
|
postData = args;
|
|
1054
847
|
}
|
|
1055
848
|
else {
|
|
1056
|
-
postData =
|
|
849
|
+
postData = objectToFormData.serialize(args, {}, null, "args");
|
|
1057
850
|
}
|
|
1058
851
|
}
|
|
1059
852
|
else {
|
|
1060
853
|
postData = new FormData();
|
|
1061
854
|
}
|
|
1062
855
|
return postData;
|
|
1063
|
-
}
|
|
856
|
+
}
|
|
1064
857
|
/**
|
|
1065
858
|
* @param {string} attributeName
|
|
1066
859
|
* @returns {any}
|
|
1067
860
|
*/
|
|
1068
|
-
|
|
1069
|
-
|
|
861
|
+
readAttribute(attributeName) {
|
|
862
|
+
const attributeNameUnderscore = inflection.underscore(attributeName);
|
|
1070
863
|
return this.readAttributeUnderscore(attributeNameUnderscore);
|
|
1071
|
-
}
|
|
864
|
+
}
|
|
1072
865
|
/**
|
|
1073
866
|
* @param {string} attributeName
|
|
1074
867
|
* @returns {any}
|
|
1075
868
|
*/
|
|
1076
|
-
|
|
869
|
+
readAttributeUnderscore(attributeName) {
|
|
1077
870
|
if (attributeName in this.changes) {
|
|
1078
871
|
return this.changes[attributeName];
|
|
1079
872
|
}
|
|
@@ -1082,26 +875,26 @@ var BaseModel = /** @class */ (function () {
|
|
|
1082
875
|
}
|
|
1083
876
|
else if (this.isNewRecord()) {
|
|
1084
877
|
// Return null if this is a new record and the attribute name is a recognized attribute
|
|
1085
|
-
|
|
878
|
+
const attributes = digg(this.modelClassData(), "attributes");
|
|
1086
879
|
if (attributeName in attributes)
|
|
1087
880
|
return null;
|
|
1088
881
|
}
|
|
1089
882
|
if (this.isPersisted()) {
|
|
1090
|
-
throw new
|
|
883
|
+
throw new AttributeNotLoadedError(`No such attribute: ${digg(this.modelClassData(), "name")}#${attributeName}: ${JSON.stringify(this.modelData)}`);
|
|
1091
884
|
}
|
|
1092
|
-
}
|
|
885
|
+
}
|
|
1093
886
|
/**
|
|
1094
887
|
* @returns {boolean}
|
|
1095
888
|
*/
|
|
1096
|
-
|
|
1097
|
-
|
|
889
|
+
isAttributeLoaded(attributeName) {
|
|
890
|
+
const attributeNameUnderscore = inflection.underscore(attributeName);
|
|
1098
891
|
if (attributeNameUnderscore in this.changes)
|
|
1099
892
|
return true;
|
|
1100
893
|
if (attributeNameUnderscore in this.modelData)
|
|
1101
894
|
return true;
|
|
1102
895
|
return false;
|
|
1103
|
-
}
|
|
1104
|
-
|
|
896
|
+
}
|
|
897
|
+
_isPresent(value) {
|
|
1105
898
|
if (!value) {
|
|
1106
899
|
return false;
|
|
1107
900
|
}
|
|
@@ -1109,32 +902,22 @@ var BaseModel = /** @class */ (function () {
|
|
|
1109
902
|
return false;
|
|
1110
903
|
}
|
|
1111
904
|
return true;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
case 3:
|
|
1129
|
-
model = _a.sent();
|
|
1130
|
-
this.relationshipsCache[args.reflectionName] = model;
|
|
1131
|
-
return [2 /*return*/, model];
|
|
1132
|
-
}
|
|
1133
|
-
});
|
|
1134
|
-
});
|
|
1135
|
-
};
|
|
1136
|
-
BaseModel.prototype._readBelongsToReflection = function (_a) {
|
|
1137
|
-
var reflectionName = _a.reflectionName;
|
|
905
|
+
}
|
|
906
|
+
async _loadBelongsToReflection(args, queryArgs = {}) {
|
|
907
|
+
if (args.reflectionName in this.relationships) {
|
|
908
|
+
return this.relationships[args.reflectionName];
|
|
909
|
+
}
|
|
910
|
+
else if (args.reflectionName in this.relationshipsCache) {
|
|
911
|
+
return this.relationshipsCache[args.reflectionName];
|
|
912
|
+
}
|
|
913
|
+
else {
|
|
914
|
+
const collection = new Collection(args, queryArgs);
|
|
915
|
+
const model = await collection.first();
|
|
916
|
+
this.relationshipsCache[args.reflectionName] = model;
|
|
917
|
+
return model;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
_readBelongsToReflection({ reflectionName }) {
|
|
1138
921
|
if (reflectionName in this.relationships) {
|
|
1139
922
|
return this.relationships[reflectionName];
|
|
1140
923
|
}
|
|
@@ -1143,70 +926,49 @@ var BaseModel = /** @class */ (function () {
|
|
|
1143
926
|
}
|
|
1144
927
|
if (this.isNewRecord())
|
|
1145
928
|
return null;
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
throw new
|
|
1149
|
-
}
|
|
929
|
+
const loadedRelationships = Object.keys(this.relationshipsCache);
|
|
930
|
+
const modelClassName = digg(this.modelClassData(), "name");
|
|
931
|
+
throw new NotLoadedError(`${modelClassName}#${reflectionName} hasn't been loaded yet. Only these were loaded: ${loadedRelationships.join(", ")}`);
|
|
932
|
+
}
|
|
1150
933
|
/**
|
|
1151
934
|
* @template {typeof import("./base-model.js").default} AssocMC
|
|
1152
935
|
* @param {import("./collection.js").CollectionArgsType<AssocMC>} args
|
|
1153
936
|
* @param {import("./collection.js").QueryArgsType} queryArgs
|
|
1154
937
|
* @returns {Promise<Array<InstanceType<AssocMC>>>}
|
|
1155
938
|
*/
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
}
|
|
1169
|
-
collection = new collection_js_1.default(args, queryArgs);
|
|
1170
|
-
return [4 /*yield*/, collection.toArray()];
|
|
1171
|
-
case 1:
|
|
1172
|
-
models = _a.sent();
|
|
1173
|
-
this.relationshipsCache[args.reflectionName] = models;
|
|
1174
|
-
return [2 /*return*/, models];
|
|
1175
|
-
}
|
|
1176
|
-
});
|
|
1177
|
-
});
|
|
1178
|
-
};
|
|
939
|
+
async _loadHasManyReflection(args, queryArgs = {}) {
|
|
940
|
+
if (args.reflectionName in this.relationships) {
|
|
941
|
+
return this.relationships[args.reflectionName];
|
|
942
|
+
}
|
|
943
|
+
else if (args.reflectionName in this.relationshipsCache) {
|
|
944
|
+
return this.relationshipsCache[args.reflectionName];
|
|
945
|
+
}
|
|
946
|
+
const collection = new Collection(args, queryArgs);
|
|
947
|
+
const models = await collection.toArray();
|
|
948
|
+
this.relationshipsCache[args.reflectionName] = models;
|
|
949
|
+
return models;
|
|
950
|
+
}
|
|
1179
951
|
/**
|
|
1180
952
|
* @template {typeof import("./base-model.js").default} AssocMC
|
|
1181
953
|
* @param {import("./collection.js").CollectionArgsType<AssocMC>} args
|
|
1182
954
|
* @param {import("./collection.js").QueryArgsType} queryArgs
|
|
1183
955
|
* @returns {Promise<InstanceType<AssocMC>>}
|
|
1184
956
|
*/
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
case 3:
|
|
1201
|
-
model = _a.sent();
|
|
1202
|
-
this.relationshipsCache[args.reflectionName] = model;
|
|
1203
|
-
return [2 /*return*/, model];
|
|
1204
|
-
}
|
|
1205
|
-
});
|
|
1206
|
-
});
|
|
1207
|
-
};
|
|
1208
|
-
BaseModel.prototype._readHasOneReflection = function (_a) {
|
|
1209
|
-
var reflectionName = _a.reflectionName;
|
|
957
|
+
async _loadHasOneReflection(args, queryArgs = {}) {
|
|
958
|
+
if (args.reflectionName in this.relationships) {
|
|
959
|
+
return this.relationships[args.reflectionName];
|
|
960
|
+
}
|
|
961
|
+
else if (args.reflectionName in this.relationshipsCache) {
|
|
962
|
+
return this.relationshipsCache[args.reflectionName];
|
|
963
|
+
}
|
|
964
|
+
else {
|
|
965
|
+
const collection = new Collection(args, queryArgs);
|
|
966
|
+
const model = await collection.first();
|
|
967
|
+
this.relationshipsCache[args.reflectionName] = model;
|
|
968
|
+
return model;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
_readHasOneReflection({ reflectionName }) {
|
|
1210
972
|
if (reflectionName in this.relationships) {
|
|
1211
973
|
return this.relationships[reflectionName];
|
|
1212
974
|
}
|
|
@@ -1216,74 +978,59 @@ var BaseModel = /** @class */ (function () {
|
|
|
1216
978
|
if (this.isNewRecord()) {
|
|
1217
979
|
return null;
|
|
1218
980
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
throw new
|
|
1222
|
-
}
|
|
1223
|
-
|
|
981
|
+
const loadedRelationships = Object.keys(this.relationshipsCache);
|
|
982
|
+
const modelClassName = digg(this.modelClassData(), "name");
|
|
983
|
+
throw new NotLoadedError(`${modelClassName}#${reflectionName} hasn't been loaded yet. Only these were loaded: ${loadedRelationships.join(", ")}`);
|
|
984
|
+
}
|
|
985
|
+
_readModelDataFromArgs(args) {
|
|
1224
986
|
this.abilities = args.data.b || {};
|
|
1225
987
|
this.collection = args.collection;
|
|
1226
988
|
this.modelData = objectToUnderscore(args.data.a);
|
|
1227
989
|
this.preloadedRelationships = args.data.r;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
990
|
+
}
|
|
991
|
+
_readPreloadedRelationships(preloaded) {
|
|
1230
992
|
if (!this.preloadedRelationships) {
|
|
1231
993
|
return;
|
|
1232
994
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
995
|
+
const relationships = digg(this.modelClassData(), "relationships");
|
|
996
|
+
for (const relationshipName in this.preloadedRelationships) {
|
|
997
|
+
const relationshipData = this.preloadedRelationships[relationshipName];
|
|
998
|
+
const relationshipClassData = relationships.find((relationship) => digg(relationship, "name") == relationshipName);
|
|
1237
999
|
if (!relationshipClassData) {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
throw new Error(
|
|
1000
|
+
const modelName = digg(this.modelClassData(), "name");
|
|
1001
|
+
const relationshipsList = relationships.map((relationship) => relationship.name).join(", ");
|
|
1002
|
+
throw new Error(`Could not find the relation ${relationshipName} on the ${modelName} model: ${relationshipsList}`);
|
|
1241
1003
|
}
|
|
1242
|
-
|
|
1243
|
-
if (relationshipName in
|
|
1244
|
-
throw new Error(
|
|
1004
|
+
const relationshipType = digg(relationshipClassData, "collectionName");
|
|
1005
|
+
if (relationshipName in this.relationshipsCache) {
|
|
1006
|
+
throw new Error(`${relationshipName} has already been loaded`);
|
|
1245
1007
|
}
|
|
1246
1008
|
if (!relationshipClassData) {
|
|
1247
|
-
throw new Error(
|
|
1009
|
+
throw new Error(`No relationship on ${digg(this.modelClassData(), "name")} by that name: ${relationshipName}`);
|
|
1248
1010
|
}
|
|
1249
1011
|
if (!relationshipData) {
|
|
1250
|
-
|
|
1251
|
-
|
|
1012
|
+
this.relationshipsCache[relationshipName] = null;
|
|
1013
|
+
this.relationships[relationshipName] = null;
|
|
1252
1014
|
}
|
|
1253
1015
|
else if (Array.isArray(relationshipData)) {
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
for (
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
this_1.relationships[relationshipName].push(model);
|
|
1016
|
+
this.relationshipsCache[relationshipName] = [];
|
|
1017
|
+
this.relationships[relationshipName] = [];
|
|
1018
|
+
for (const relationshipId of relationshipData) {
|
|
1019
|
+
const model = preloaded.getModel(relationshipType, relationshipId);
|
|
1020
|
+
this.relationshipsCache[relationshipName].push(model);
|
|
1021
|
+
this.relationships[relationshipName].push(model);
|
|
1261
1022
|
}
|
|
1262
1023
|
}
|
|
1263
1024
|
else {
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1025
|
+
const model = preloaded.getModel(relationshipType, relationshipData);
|
|
1026
|
+
this.relationshipsCache[relationshipName] = model;
|
|
1027
|
+
this.relationships[relationshipName] = model;
|
|
1267
1028
|
}
|
|
1268
|
-
};
|
|
1269
|
-
var this_1 = this;
|
|
1270
|
-
for (var relationshipName in this.preloadedRelationships) {
|
|
1271
|
-
_loop_1(relationshipName);
|
|
1272
1029
|
}
|
|
1273
|
-
}
|
|
1030
|
+
}
|
|
1274
1031
|
/**
|
|
1275
1032
|
* @returns {number|string}
|
|
1276
1033
|
*/
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
/**
|
|
1280
|
-
* @param {ValidationErrors} validationErrors
|
|
1281
|
-
* @returns {CustomEvent}
|
|
1282
|
-
*/
|
|
1283
|
-
BaseModel.newCustomEvent = function (validationErrors) {
|
|
1284
|
-
return new CustomEvent("validation-errors", { detail: validationErrors });
|
|
1285
|
-
};
|
|
1286
|
-
return BaseModel;
|
|
1287
|
-
}());
|
|
1288
|
-
exports.default = BaseModel;
|
|
1034
|
+
primaryKey() { return this.readAttributeUnderscore(this.modelClass().primaryKey()); }
|
|
1035
|
+
}
|
|
1289
1036
|
//# sourceMappingURL=base-model.js.map
|