@kaspernj/api-maker 1.0.2011 → 1.0.2013
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/{.eslintrc.cjs → .eslintrc.js} +10 -1
- package/README.md +35 -0
- package/android/build.gradle +43 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/api_maker/ApiMakerModule.kt +50 -0
- package/android/src/main/java/expo/modules/api_maker/ApiMakerView.kt +30 -0
- package/build/api.js +120 -0
- package/build/attribute-not-loaded-error.js +2 -0
- package/build/base-component.js +5 -0
- package/build/base-error.js +33 -0
- package/build/base-model/attribute.js +25 -0
- package/build/base-model/column.js +11 -0
- package/build/base-model/reflection.js +14 -0
- package/build/base-model/scope.js +11 -0
- package/build/base-model.js +828 -0
- package/build/bootstrap/attribute-row.js +135 -0
- package/build/bootstrap/attribute-rows.js +31 -0
- package/build/bootstrap/card.js +138 -0
- package/build/bootstrap/checkbox.js +97 -0
- package/build/bootstrap/checkboxes.js +183 -0
- package/build/bootstrap/index.js +2 -0
- package/build/bootstrap/input.js +129 -0
- package/build/bootstrap/invalid-feedback.js +27 -0
- package/build/bootstrap/paginate.js +150 -0
- package/build/bootstrap/radio-buttons.js +72 -0
- package/build/bootstrap/select.js +88 -0
- package/build/bootstrap/sort-link.js +131 -0
- package/build/cable-connection-pool.js +128 -0
- package/build/cable-subscription-pool.js +207 -0
- package/build/cable-subscription.js +21 -0
- package/build/cache-key-generator.js +81 -0
- package/build/can-can.js +134 -0
- package/build/channels-consumer.js +9 -0
- package/build/collection-loader.js +48 -0
- package/build/collection.js +280 -0
- package/build/command-submit-data.js +81 -0
- package/build/commands-pool.js +195 -0
- package/build/compose.js +9 -0
- package/build/config.js +62 -0
- package/build/custom-error.js +5 -0
- package/build/data-set-to-attributes.js +10 -0
- package/build/deserializer.js +56 -0
- package/build/destroy-error.js +5 -0
- package/build/devise.js +112 -0
- package/build/draggable-sort/controller.js +136 -0
- package/build/draggable-sort/index.js +114 -0
- package/build/draggable-sort/item.js +188 -0
- package/build/error-logger.js +101 -0
- package/build/error-messages.js +13 -0
- package/build/event-connection.js +32 -0
- package/build/event-emitter-listener.js +15 -0
- package/build/event-model-class.js +24 -0
- package/build/events.js +5 -0
- package/build/flash-message.js +79 -0
- package/build/form.js +83 -0
- package/build/history-expo.js +20 -0
- package/build/history-react-native.js +20 -0
- package/build/history.js +3 -0
- package/build/index.js +3 -0
- package/build/inputs/attachment.js +133 -0
- package/build/inputs/auto-submit.js +36 -0
- package/build/inputs/checkbox.js +138 -0
- package/build/inputs/checkboxes.js +112 -0
- package/build/inputs/id-for-component.js +15 -0
- package/build/inputs/input-wrapper.js +19 -0
- package/build/inputs/input.js +243 -0
- package/build/inputs/money.js +179 -0
- package/build/inputs/name-for-component.js +13 -0
- package/build/inputs/select.js +93 -0
- package/build/instance-of-class-name.js +23 -0
- package/build/is-expo.js +22 -0
- package/build/key-value-store.js +53 -0
- package/build/link.js +73 -0
- package/build/logger.js +30 -0
- package/build/modal.js +38 -0
- package/build/model-class-require.js +13 -0
- package/build/model-events.js +30 -0
- package/build/model-name.js +28 -0
- package/build/model-prop-type.js +101 -0
- package/build/model-recipes-loader.js +32 -0
- package/build/model-recipes-model-loader.js +357 -0
- package/build/models-response-reader.js +40 -0
- package/build/models.js +8 -0
- package/build/money-formatter.js +78 -0
- package/build/not-loaded-error.js +2 -0
- package/build/params.js +61 -0
- package/build/preloaded.js +38 -0
- package/build/resize-observer.js +11 -0
- package/build/result.js +13 -0
- package/build/router/route.js +270 -0
- package/build/router/switch.js +72 -0
- package/build/router.js +59 -0
- package/build/routes-native.js +202 -0
- package/build/routes.js +50 -0
- package/build/run-last.js +35 -0
- package/build/serializer.js +63 -0
- package/build/services.js +20 -0
- package/build/session-status-updater.js +134 -0
- package/build/source-maps-loader.js +184 -0
- package/build/super-admin/config-reader.js +85 -0
- package/build/super-admin/edit-page/edit-attribute-checkbox.js +85 -0
- package/build/super-admin/edit-page/edit-attribute-content.js +55 -0
- package/build/super-admin/edit-page/edit-attribute-input.js +79 -0
- package/build/super-admin/edit-page/edit-attribute.js +77 -0
- package/build/super-admin/edit-page.js +123 -0
- package/build/super-admin/has-edit-config.js +12 -0
- package/build/super-admin/index-page.js +25 -0
- package/build/super-admin/index.js +181 -0
- package/build/super-admin/layout/header/index.js +161 -0
- package/build/super-admin/layout/index.js +164 -0
- package/build/super-admin/layout/menu/index.js +206 -0
- package/build/super-admin/layout/menu/menu-content.js +46 -0
- package/build/super-admin/layout/menu/menu-item.js +84 -0
- package/build/super-admin/layout/no-access.js +27 -0
- package/build/super-admin/model-class-table.js +61 -0
- package/build/super-admin/models.js +8 -0
- package/build/super-admin/show-nav.js +51 -0
- package/build/super-admin/show-page/belongs-to-attribute-row.js +29 -0
- package/build/super-admin/show-page/index.js +141 -0
- package/build/super-admin/show-reflection-actions.js +47 -0
- package/build/super-admin/show-reflection-link.js +48 -0
- package/build/super-admin/show-reflection-page.js +48 -0
- package/build/table/column-content.js +117 -0
- package/build/table/column-identifier.js +18 -0
- package/build/table/column-visible.js +7 -0
- package/build/table/components/column.js +21 -0
- package/build/table/components/flat-list.js +21 -0
- package/build/table/components/header.js +26 -0
- package/build/table/components/row.js +26 -0
- package/build/table/filters/attribute-element.js +44 -0
- package/build/table/filters/filter-form.js +402 -0
- package/build/table/filters/filter.js +90 -0
- package/build/table/filters/index.js +184 -0
- package/build/table/filters/load-search-modal.js +175 -0
- package/build/table/filters/reflection-element.js +37 -0
- package/build/table/filters/save-search-modal.js +88 -0
- package/build/table/filters/scope-element.js +42 -0
- package/build/table/header-column-content.js +68 -0
- package/build/table/header-column.js +144 -0
- package/build/table/header-select.js +105 -0
- package/build/table/model-callback-args.js +10 -0
- package/build/table/model-column.js +97 -0
- package/build/table/model-row.js +193 -0
- package/build/table/select-calculator.js +63 -0
- package/build/table/settings/column-row.js +97 -0
- package/build/table/settings/download-action.js +79 -0
- package/build/table/settings/index.js +92 -0
- package/build/table/table-settings.js +219 -0
- package/build/table/table.js +972 -0
- package/build/table/use-sorting.js +34 -0
- package/build/table/widths.js +75 -0
- package/build/table/worker-plugins-check-all-checkbox.js +125 -0
- package/build/table/worker-plugins-checkbox.js +115 -0
- package/build/translated-attributes.js +10 -0
- package/build/translated-collections.js +12 -0
- package/build/updated-attribute.js +76 -0
- package/build/url-encode.js +15 -0
- package/build/use-breakpoint.js +71 -0
- package/build/use-can-can.js +55 -0
- package/build/use-collection.js +225 -0
- package/build/use-created-event.js +52 -0
- package/build/use-current-user.js +76 -0
- package/build/use-destroyed-event.js +60 -0
- package/build/use-event-emitter.js +13 -0
- package/build/use-event-listener.js +16 -0
- package/build/use-input.js +137 -0
- package/build/use-model-event.js +60 -0
- package/build/use-model.js +169 -0
- package/build/use-resize-observer.js +23 -0
- package/build/use-router.js +104 -0
- package/build/use-screen-layout.js +39 -0
- package/build/use-styles.js +41 -0
- package/build/use-updated-event.js +60 -0
- package/build/use-validation-errors.js +30 -0
- package/build/utils/card.js +51 -0
- package/build/utils/checkbox.js +78 -0
- package/build/utils/checkboxes.js +163 -0
- package/build/utils/default-style.js +18 -0
- package/build/utils/icon.js +23 -0
- package/build/utils/invalid-feedback.js +19 -0
- package/build/utils/modal.js +62 -0
- package/build/utils/text.js +44 -0
- package/build/validation-error.js +28 -0
- package/build/validation-errors.js +98 -0
- package/build/with-api-maker.js +29 -0
- package/build/with-collection.js +14 -0
- package/build/with-current-user.js +10 -0
- package/build/with-model.js +15 -0
- package/build/with-router.js +22 -0
- package/expo-module.config.json +17 -0
- package/ios/ApiMaker.podspec +29 -0
- package/ios/ApiMakerModule.swift +48 -0
- package/ios/ApiMakerView.swift +38 -0
- package/package.json +49 -46
- package/src/{api.mjs → api.js} +38 -37
- package/src/base-component.jsx +5 -0
- package/src/{base-error.mjs → base-error.js} +4 -6
- package/src/base-model/attribute.js +33 -0
- package/src/base-model/column.js +13 -0
- package/src/base-model/reflection.js +15 -0
- package/src/base-model/scope.js +12 -0
- package/src/{base-model.mjs → base-model.js} +302 -144
- package/src/bootstrap/attribute-row.jsx +135 -0
- package/src/bootstrap/attribute-rows.jsx +27 -0
- package/src/bootstrap/card.jsx +149 -0
- package/src/bootstrap/checkbox.jsx +86 -0
- package/src/bootstrap/checkboxes.jsx +185 -0
- package/src/bootstrap/index.js +0 -0
- package/src/bootstrap/input.jsx +173 -0
- package/src/bootstrap/invalid-feedback.jsx +31 -0
- package/src/bootstrap/paginate.jsx +187 -0
- package/src/bootstrap/radio-buttons.jsx +87 -0
- package/src/bootstrap/select.jsx +110 -0
- package/src/bootstrap/sort-link.jsx +106 -0
- package/src/{cable-connection-pool.mjs → cable-connection-pool.js} +16 -36
- package/src/{cable-subscription-pool.mjs → cable-subscription-pool.js} +26 -21
- package/src/{cable-subscription.mjs → cable-subscription.js} +6 -4
- package/src/cache-key-generator.js +100 -0
- package/src/{can-can.mjs → can-can.js} +13 -12
- package/src/channels-consumer.js +10 -0
- package/src/collection-loader.jsx +58 -224
- package/src/{collection.mjs → collection.js} +98 -44
- package/src/{command-submit-data.mjs → command-submit-data.js} +2 -7
- package/src/{commands-pool.mjs → commands-pool.js} +57 -41
- package/src/compose.js +11 -0
- package/src/{config.mjs → config.js} +6 -2
- package/src/{custom-error.mjs → custom-error.js} +1 -1
- package/src/data-set-to-attributes.js +13 -0
- package/src/{deserializer.mjs → deserializer.js} +3 -3
- package/src/destroy-error.js +7 -0
- package/src/devise.js +129 -0
- package/src/draggable-sort/controller.js +137 -0
- package/src/draggable-sort/index.jsx +108 -0
- package/src/draggable-sort/item.jsx +174 -0
- package/src/{error-logger.mjs → error-logger.js} +12 -7
- package/src/{error-messages.mjs → error-messages.js} +1 -0
- package/src/event-connection.jsx +1 -1
- package/src/event-emitter-listener.jsx +8 -27
- package/src/event-model-class.jsx +2 -4
- package/src/events.js +7 -0
- package/src/flash-message.js +70 -0
- package/src/form.jsx +91 -0
- package/src/history-expo.js +23 -0
- package/src/history-react-native.js +25 -0
- package/src/history.js +3 -0
- package/src/index.js +3 -0
- package/src/inputs/attachment.jsx +108 -0
- package/src/inputs/auto-submit.js +37 -0
- package/src/inputs/checkbox.jsx +125 -0
- package/src/inputs/checkboxes.jsx +116 -0
- package/src/inputs/id-for-component.js +15 -0
- package/src/inputs/input-wrapper.jsx +16 -0
- package/src/inputs/input.jsx +260 -0
- package/src/inputs/money.jsx +187 -0
- package/src/inputs/name-for-component.js +15 -0
- package/src/inputs/select.jsx +104 -0
- package/src/is-expo.js +18 -0
- package/src/{key-value-store.mjs → key-value-store.js} +1 -1
- package/src/link.jsx +54 -9
- package/src/logger.js +38 -0
- package/src/modal.jsx +37 -0
- package/src/model-class-require.js +17 -0
- package/src/{model-events.mjs → model-events.js} +1 -1
- package/src/{model-name.mjs → model-name.js} +8 -8
- package/src/{model-recipes-loader.mjs → model-recipes-loader.js} +1 -1
- package/src/{model-recipes-model-loader.mjs → model-recipes-model-loader.js} +5 -5
- package/src/{models-response-reader.mjs → models-response-reader.js} +3 -4
- package/src/models.js +7 -0
- package/src/{models.mjs.erb → models.js.erb} +6 -3
- package/src/{money-formatter.mjs → money-formatter.js} +5 -4
- package/src/{params.mjs → params.js} +17 -7
- package/src/{preloaded.mjs → preloaded.js} +2 -2
- package/src/resize-observer.jsx +10 -0
- package/src/result.js +13 -0
- package/src/router/route.jsx +246 -0
- package/src/router/switch.jsx +76 -0
- package/src/router.jsx +23 -21
- package/src/{routes-native.mjs → routes-native.js} +12 -6
- package/src/{routes.mjs → routes.js} +1 -1
- package/src/run-last.js +39 -0
- package/src/{serializer.mjs → serializer.js} +2 -2
- package/src/{services.mjs → services.js} +1 -1
- package/src/session-status-updater.js +172 -0
- package/src/{source-maps-loader.mjs → source-maps-loader.js} +54 -28
- package/src/super-admin/config-reader.jsx +93 -0
- package/src/super-admin/edit-page/edit-attribute-checkbox.jsx +81 -0
- package/src/super-admin/edit-page/edit-attribute-content.jsx +57 -0
- package/src/super-admin/edit-page/edit-attribute-input.jsx +71 -0
- package/src/super-admin/edit-page/edit-attribute.jsx +81 -0
- package/src/super-admin/edit-page.jsx +117 -0
- package/src/super-admin/has-edit-config.js +15 -0
- package/src/super-admin/index-page.jsx +23 -0
- package/src/super-admin/index.jsx +197 -0
- package/src/super-admin/layout/header/index.jsx +144 -0
- package/src/super-admin/layout/header/style.scss +45 -0
- package/src/super-admin/layout/index.jsx +154 -0
- package/src/super-admin/layout/menu/index.jsx +171 -0
- package/src/super-admin/layout/menu/menu-content.jsx +43 -0
- package/src/super-admin/layout/menu/menu-item.jsx +70 -0
- package/src/super-admin/layout/menu/style.scss +11 -0
- package/src/super-admin/layout/no-access.jsx +26 -0
- package/src/super-admin/model-class-table.jsx +66 -0
- package/src/super-admin/models.js +11 -0
- package/src/super-admin/show-nav.jsx +44 -0
- package/src/super-admin/show-page/belongs-to-attribute-row.jsx +30 -0
- package/src/super-admin/show-page/index.jsx +141 -0
- package/src/super-admin/show-reflection-actions.jsx +49 -0
- package/src/super-admin/show-reflection-link.jsx +40 -0
- package/src/super-admin/show-reflection-page.jsx +47 -0
- package/src/super-admin/stylesheets/variables.scss +11 -0
- package/src/table/column-content.jsx +122 -0
- package/src/table/column-identifier.js +23 -0
- package/src/table/column-visible.js +7 -0
- package/src/table/components/column.jsx +19 -0
- package/src/table/components/flat-list.jsx +19 -0
- package/src/table/components/header.jsx +21 -0
- package/src/table/components/row.jsx +23 -0
- package/src/table/filters/attribute-element.jsx +47 -0
- package/src/table/filters/filter-form.jsx +407 -0
- package/src/table/filters/filter.jsx +70 -0
- package/src/table/filters/index.jsx +170 -0
- package/src/table/filters/load-search-modal.jsx +146 -0
- package/src/table/filters/reflection-element.jsx +38 -0
- package/src/table/filters/save-search-modal.jsx +74 -0
- package/src/table/filters/scope-element.jsx +44 -0
- package/src/table/header-column-content.jsx +55 -0
- package/src/table/header-column.jsx +129 -0
- package/src/table/header-select.jsx +73 -0
- package/src/table/model-callback-args.js +10 -0
- package/src/table/model-column.jsx +82 -0
- package/src/table/model-row.jsx +136 -0
- package/src/table/select-calculator.js +65 -0
- package/src/table/settings/column-row.jsx +93 -0
- package/src/table/settings/download-action.jsx +68 -0
- package/src/table/settings/index.jsx +65 -0
- package/src/table/table-settings.js +263 -0
- package/src/table/table.jsx +950 -0
- package/src/table/use-sorting.js +35 -0
- package/src/table/variables.scss +11 -0
- package/src/table/widths.jsx +87 -0
- package/src/table/worker-plugins-check-all-checkbox.jsx +112 -0
- package/src/table/worker-plugins-checkbox.jsx +104 -0
- package/src/translated-attributes.js +11 -0
- package/src/{translated-collections.mjs → translated-collections.js} +3 -2
- package/src/updated-attribute.jsx +1 -1
- package/src/url-encode.js +18 -0
- package/src/use-breakpoint.js +87 -0
- package/src/use-can-can.js +55 -0
- package/src/use-collection.js +280 -0
- package/src/use-created-event.js +55 -0
- package/src/use-current-user.js +88 -0
- package/src/use-destroyed-event.js +60 -0
- package/src/use-event-emitter.js +15 -0
- package/src/use-event-listener.js +19 -0
- package/src/use-input.js +157 -0
- package/src/use-model-event.js +60 -0
- package/src/use-model.js +189 -0
- package/src/use-resize-observer.js +24 -0
- package/src/use-router.jsx +128 -0
- package/src/use-screen-layout.js +49 -0
- package/src/use-styles.js +50 -0
- package/src/use-updated-event.js +60 -0
- package/src/use-validation-errors.js +33 -0
- package/src/utils/card.jsx +49 -0
- package/src/utils/checkbox.jsx +80 -0
- package/src/utils/checkboxes.jsx +158 -0
- package/src/utils/default-style.jsx +25 -0
- package/src/utils/icon.jsx +21 -0
- package/src/utils/invalid-feedback.jsx +20 -0
- package/src/utils/modal.jsx +60 -0
- package/src/utils/text.jsx +38 -0
- package/src/{validation-error.mjs → validation-error.js} +9 -5
- package/src/{validation-errors.mjs → validation-errors.js} +15 -27
- package/src/with-api-maker.jsx +31 -0
- package/src/with-collection.jsx +17 -0
- package/src/with-current-user.jsx +7 -25
- package/src/with-model.jsx +16 -0
- package/src/with-router.jsx +7 -129
- package/__tests__/base-model.test.js +0 -71
- package/__tests__/cable-connection-pool.test.js +0 -227
- package/__tests__/cable-subscription-pool.test.js +0 -26
- package/__tests__/can-can.test.js +0 -34
- package/__tests__/collection.test.js +0 -51
- package/__tests__/custom-error.test.js +0 -13
- package/__tests__/model-name.test.js +0 -34
- package/__tests__/model-prop-type.test.js +0 -113
- package/__tests__/params.test.js +0 -40
- package/__tests__/routes-native.test.js +0 -103
- package/__tests__/routes.test.js +0 -46
- package/__tests__/serializer.test.js +0 -30
- package/__tests__/support/task.js +0 -27
- package/__tests__/support/user.js +0 -32
- package/index.js +0 -1
- package/jest.config.js +0 -4
- package/src/can-can-loader.jsx +0 -54
- package/src/channels-consumer.mjs +0 -3
- package/src/destroy-error.mjs +0 -7
- package/src/devise.mjs +0 -122
- package/src/event-created.jsx +0 -65
- package/src/event-destroyed.jsx +0 -29
- package/src/event-listener.jsx +0 -38
- package/src/event-updated.jsx +0 -74
- package/src/logger.mjs +0 -25
- package/src/model-class-require.mjs +0 -10
- package/src/model-load-wrapper.jsx +0 -116
- package/src/result.mjs +0 -29
- package/src/session-status-updater.mjs +0 -116
- package/webpack.config.js +0 -15
- /package/src/{attribute-not-loaded-error.mjs → attribute-not-loaded-error.js} +0 -0
- /package/src/{instance-of-class-name.mjs → instance-of-class-name.js} +0 -0
- /package/src/{model-prop-type.mjs → model-prop-type.js} +0 -0
- /package/src/{not-loaded-error.mjs → not-loaded-error.js} +0 -0
- /package/src/{translated-collections-data.mjs.erb → translated-collections-data.js.erb} +0 -0
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import cloneDeep from "clone-deep"
|
|
2
|
-
import CommandsPool from "./commands-pool
|
|
2
|
+
import CommandsPool from "./commands-pool"
|
|
3
3
|
import {digg} from "diggerize"
|
|
4
|
-
import inflection from "inflection"
|
|
4
|
+
import * as inflection from "inflection"
|
|
5
5
|
import {incorporate} from "incorporator"
|
|
6
|
-
import modelClassRequire from "./model-class-require
|
|
7
|
-
import Result from "./result
|
|
6
|
+
import modelClassRequire from "./model-class-require"
|
|
7
|
+
import Result from "./result"
|
|
8
|
+
import uniqunize from "uniqunize"
|
|
8
9
|
|
|
9
|
-
class ApiMakerCollection {
|
|
10
|
-
|
|
10
|
+
export default class ApiMakerCollection {
|
|
11
|
+
static apiMakerType = "Collection"
|
|
12
|
+
|
|
13
|
+
constructor(args, queryArgs = {}) {
|
|
11
14
|
this.queryArgs = queryArgs
|
|
12
15
|
this.args = args
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
abilities
|
|
18
|
+
abilities(originalAbilities) {
|
|
16
19
|
const newAbilities = {}
|
|
17
20
|
|
|
18
21
|
for (const originalAbilityName in originalAbilities) {
|
|
@@ -31,21 +34,21 @@ class ApiMakerCollection {
|
|
|
31
34
|
return this._merge({abilities: newAbilities})
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
accessibleBy
|
|
37
|
+
accessibleBy(abilityName) {
|
|
35
38
|
return this._merge({accessibleBy: inflection.underscore(abilityName)})
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
async count
|
|
41
|
+
async count() {
|
|
39
42
|
const response = await this.clone()._merge({count: true})._response()
|
|
40
43
|
|
|
41
44
|
return digg(response, "count")
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
distinct
|
|
47
|
+
distinct() {
|
|
45
48
|
return this._merge({distinct: true})
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
async each
|
|
51
|
+
async each(callback) {
|
|
49
52
|
const array = await this.toArray()
|
|
50
53
|
|
|
51
54
|
for (const model in array) {
|
|
@@ -53,12 +56,24 @@ class ApiMakerCollection {
|
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
except(...keys) {
|
|
60
|
+
for (const key of keys) {
|
|
61
|
+
if (key == "page") {
|
|
62
|
+
delete this.queryArgs[key]
|
|
63
|
+
} else {
|
|
64
|
+
throw new Error(`Unhandled key: ${key}`)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return this
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async first() {
|
|
57
72
|
const models = await this.toArray()
|
|
58
73
|
return models[0]
|
|
59
74
|
}
|
|
60
75
|
|
|
61
|
-
groupBy
|
|
76
|
+
groupBy(...arrayOfTablesAndColumns) {
|
|
62
77
|
const arrayOfTablesAndColumnsWithLowercaseColumns = arrayOfTablesAndColumns.map((tableAndColumn) => {
|
|
63
78
|
if (Array.isArray(tableAndColumn)) {
|
|
64
79
|
return [tableAndColumn[0], tableAndColumn[1].toLowerCase()]
|
|
@@ -74,18 +89,18 @@ class ApiMakerCollection {
|
|
|
74
89
|
})
|
|
75
90
|
}
|
|
76
91
|
|
|
77
|
-
isLoaded
|
|
92
|
+
isLoaded() {
|
|
78
93
|
if (this.args.reflectionName in this.args.model.relationshipsCache)
|
|
79
94
|
return true
|
|
80
95
|
|
|
81
96
|
return false
|
|
82
97
|
}
|
|
83
98
|
|
|
84
|
-
limit
|
|
99
|
+
limit(amount) {
|
|
85
100
|
return this._merge({limit: amount})
|
|
86
101
|
}
|
|
87
102
|
|
|
88
|
-
|
|
103
|
+
preloaded() {
|
|
89
104
|
if (!(this.args.reflectionName in this.args.model.relationshipsCache)) {
|
|
90
105
|
throw new Error(`${this.args.reflectionName} hasnt been loaded yet`)
|
|
91
106
|
}
|
|
@@ -93,22 +108,62 @@ class ApiMakerCollection {
|
|
|
93
108
|
return this.args.model.relationshipsCache[this.args.reflectionName]
|
|
94
109
|
}
|
|
95
110
|
|
|
96
|
-
|
|
111
|
+
loaded() {
|
|
112
|
+
const {model, reflectionName} = this.args
|
|
113
|
+
|
|
114
|
+
if (reflectionName in model.relationships) {
|
|
115
|
+
return model.relationships[reflectionName]
|
|
116
|
+
} else if (reflectionName in model.relationshipsCache) {
|
|
117
|
+
return model.relationshipsCache[reflectionName]
|
|
118
|
+
} else if (model.isNewRecord()) {
|
|
119
|
+
const reflectionNameUnderscore = inflection.underscore(reflectionName)
|
|
120
|
+
|
|
121
|
+
// Initialize as empty and try again to return the empty result
|
|
122
|
+
this.set([])
|
|
123
|
+
|
|
124
|
+
return digg(model.relationships, reflectionNameUnderscore)
|
|
125
|
+
} else {
|
|
126
|
+
const relationshipsLoaded = uniqunize(Object.keys(model.relationships).concat(Object.keys(model.relationshipsCache)))
|
|
127
|
+
|
|
128
|
+
throw new Error(`${reflectionName} hasnt been loaded yet on ${model.modelClassData().name}. Loaded was: ${relationshipsLoaded.join(", ")}`)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Replaces the relationships with the given new collection.
|
|
133
|
+
set(newCollection) {
|
|
134
|
+
this.args.model.relationships[this.args.reflectionName] = newCollection
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Pushes another model onto the given collection.
|
|
138
|
+
push(newModel) {
|
|
139
|
+
if (!(this.args.reflectionName in this.args.model.relationships)) {
|
|
140
|
+
this.args.model.relationships[this.args.reflectionName] = []
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this.args.model.relationships[this.args.reflectionName].push(newModel)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Array shortcuts
|
|
147
|
+
find = (...args) => this.loaded().find(...args)
|
|
148
|
+
forEach = (...args) => this.loaded().forEach(...args)
|
|
149
|
+
map = (...args) => this.loaded().map(...args)
|
|
150
|
+
|
|
151
|
+
preload(preloadValue) {
|
|
97
152
|
return this._merge({preload: preloadValue})
|
|
98
153
|
}
|
|
99
154
|
|
|
100
|
-
page
|
|
155
|
+
page(page) {
|
|
101
156
|
if (!page)
|
|
102
157
|
page = 1
|
|
103
158
|
|
|
104
159
|
return this._merge({page})
|
|
105
160
|
}
|
|
106
161
|
|
|
107
|
-
pageKey
|
|
162
|
+
pageKey(pageKey) {
|
|
108
163
|
return this._merge({pageKey})
|
|
109
164
|
}
|
|
110
165
|
|
|
111
|
-
params
|
|
166
|
+
params() {
|
|
112
167
|
let params = {}
|
|
113
168
|
|
|
114
169
|
if (this.queryArgs.params) params = incorporate(params, this.queryArgs.params)
|
|
@@ -122,44 +177,47 @@ class ApiMakerCollection {
|
|
|
122
177
|
if (this.queryArgs.preload) params.preload = this.queryArgs.preload
|
|
123
178
|
if (this.queryArgs.page) params.page = this.queryArgs.page
|
|
124
179
|
if (this.queryArgs.per) params.per = this.queryArgs.per
|
|
180
|
+
if (this.queryArgs.search) params.search = this.queryArgs.search
|
|
125
181
|
if (this.queryArgs.select) params.select = this.queryArgs.select
|
|
126
182
|
if (this.queryArgs.selectColumns) params.select_columns = this.queryArgs.selectColumns
|
|
127
183
|
|
|
128
184
|
return params
|
|
129
185
|
}
|
|
130
186
|
|
|
131
|
-
per
|
|
187
|
+
per(per) {
|
|
132
188
|
return this._merge({per})
|
|
133
189
|
}
|
|
134
190
|
|
|
135
|
-
perKey
|
|
191
|
+
perKey(perKey) {
|
|
136
192
|
return this._merge({perKey})
|
|
137
193
|
}
|
|
138
194
|
|
|
139
|
-
ransack
|
|
140
|
-
if (params) {
|
|
141
|
-
this._merge({ransack: params})
|
|
142
|
-
}
|
|
143
|
-
|
|
195
|
+
ransack(params) {
|
|
196
|
+
if (params) this._merge({ransack: params})
|
|
144
197
|
return this
|
|
145
198
|
}
|
|
146
199
|
|
|
147
|
-
async result
|
|
200
|
+
async result() {
|
|
148
201
|
const response = await this._response()
|
|
149
202
|
const models = digg(response, "collection")
|
|
150
203
|
|
|
151
|
-
this.
|
|
204
|
+
this._addQueryToModels(models)
|
|
152
205
|
|
|
153
206
|
const result = new Result({collection: this, models, response})
|
|
154
207
|
|
|
155
208
|
return result
|
|
156
209
|
}
|
|
157
210
|
|
|
158
|
-
|
|
211
|
+
search(params) {
|
|
212
|
+
if (params) this._merge({search: params})
|
|
213
|
+
return this
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
searchKey(searchKey) {
|
|
159
217
|
return this._merge({searchKey})
|
|
160
218
|
}
|
|
161
219
|
|
|
162
|
-
select
|
|
220
|
+
select(originalSelect) {
|
|
163
221
|
const newSelect = {}
|
|
164
222
|
|
|
165
223
|
for (const originalModelName in originalSelect) {
|
|
@@ -178,7 +236,7 @@ class ApiMakerCollection {
|
|
|
178
236
|
return this._merge({select: newSelect})
|
|
179
237
|
}
|
|
180
238
|
|
|
181
|
-
selectColumns
|
|
239
|
+
selectColumns(originalSelect) {
|
|
182
240
|
const newSelect = {}
|
|
183
241
|
|
|
184
242
|
for (const originalModelName in originalSelect) {
|
|
@@ -197,45 +255,45 @@ class ApiMakerCollection {
|
|
|
197
255
|
return this._merge({selectColumns: newSelect})
|
|
198
256
|
}
|
|
199
257
|
|
|
200
|
-
sort
|
|
258
|
+
sort(sortBy) {
|
|
201
259
|
return this._merge({ransack: {s: sortBy}})
|
|
202
260
|
}
|
|
203
261
|
|
|
204
|
-
async toArray
|
|
262
|
+
async toArray() {
|
|
205
263
|
const response = await this._response()
|
|
206
264
|
const models = digg(response, "collection")
|
|
207
265
|
|
|
208
|
-
this.
|
|
266
|
+
this._addQueryToModels(models)
|
|
209
267
|
|
|
210
268
|
return models
|
|
211
269
|
}
|
|
212
270
|
|
|
213
|
-
modelClass
|
|
271
|
+
modelClass() {
|
|
214
272
|
const modelName = digg(this.args.modelClass.modelClassData(), "name")
|
|
215
273
|
|
|
216
274
|
return modelClassRequire(modelName)
|
|
217
275
|
}
|
|
218
276
|
|
|
219
|
-
clone
|
|
277
|
+
clone() {
|
|
220
278
|
const clonedQueryArgs = cloneDeep(this.queryArgs)
|
|
221
279
|
|
|
222
280
|
return new ApiMakerCollection(this.args, clonedQueryArgs)
|
|
223
281
|
}
|
|
224
282
|
|
|
225
283
|
// This is needed when reloading a version of the model with the same selected attributes and preloads
|
|
226
|
-
|
|
284
|
+
_addQueryToModels(models) {
|
|
227
285
|
for(const model of models) {
|
|
228
286
|
model.collection = this
|
|
229
287
|
}
|
|
230
288
|
}
|
|
231
289
|
|
|
232
|
-
_merge
|
|
290
|
+
_merge(newQueryArgs) {
|
|
233
291
|
incorporate(this.queryArgs, newQueryArgs)
|
|
234
292
|
|
|
235
293
|
return this
|
|
236
294
|
}
|
|
237
295
|
|
|
238
|
-
_response
|
|
296
|
+
_response() {
|
|
239
297
|
const modelClassData = this.args.modelClass.modelClassData()
|
|
240
298
|
|
|
241
299
|
return CommandsPool.addCommand(
|
|
@@ -249,7 +307,3 @@ class ApiMakerCollection {
|
|
|
249
307
|
)
|
|
250
308
|
}
|
|
251
309
|
}
|
|
252
|
-
|
|
253
|
-
ApiMakerCollection.apiMakerType = "Collection"
|
|
254
|
-
|
|
255
|
-
export default ApiMakerCollection
|
|
@@ -7,13 +7,8 @@ export default class ApiMakerCommandSubmitData {
|
|
|
7
7
|
this.jsonData = this.traverseObject(this.data, "json")
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
getFilesCount ()
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
getJsonData () {
|
|
15
|
-
return this.jsonData
|
|
16
|
-
}
|
|
10
|
+
getFilesCount = () => this.filesCount
|
|
11
|
+
getJsonData = () => this.jsonData
|
|
17
12
|
|
|
18
13
|
getRawData () {
|
|
19
14
|
if (!this.rawData) {
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import Api from "./api
|
|
2
|
-
import CommandSubmitData from "./command-submit-data
|
|
3
|
-
import CustomError from "./custom-error
|
|
4
|
-
import DestroyError from "./destroy-error
|
|
5
|
-
import Deserializer from "./deserializer
|
|
1
|
+
import Api from "./api"
|
|
2
|
+
import CommandSubmitData from "./command-submit-data"
|
|
3
|
+
import CustomError from "./custom-error"
|
|
4
|
+
import DestroyError from "./destroy-error"
|
|
5
|
+
import Deserializer from "./deserializer"
|
|
6
6
|
import {dig, digg} from "diggerize"
|
|
7
|
+
import events from "./events"
|
|
7
8
|
import FormDataObjectizer from "form-data-objectizer"
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
9
|
+
import RunLast from "./run-last"
|
|
10
|
+
import Serializer from "./serializer"
|
|
11
|
+
import SessionStatusUpdater from "./session-status-updater"
|
|
12
|
+
import ValidationError from "./validation-error"
|
|
13
|
+
import {ValidationErrors} from "./validation-errors"
|
|
11
14
|
|
|
12
15
|
const shared = {}
|
|
13
16
|
|
|
14
17
|
export default class ApiMakerCommandsPool {
|
|
15
|
-
static addCommand
|
|
18
|
+
static addCommand(data, args = {}) {
|
|
16
19
|
let pool
|
|
17
20
|
|
|
18
21
|
if (args.instant) {
|
|
@@ -24,25 +27,25 @@ export default class ApiMakerCommandsPool {
|
|
|
24
27
|
const promiseResult = pool.addCommand(data)
|
|
25
28
|
|
|
26
29
|
if (args.instant) {
|
|
27
|
-
pool.
|
|
30
|
+
pool.flushRunLast.run()
|
|
28
31
|
} else {
|
|
29
|
-
pool.
|
|
32
|
+
pool.flushRunLast.queue()
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
return promiseResult
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
static current
|
|
38
|
+
static current() {
|
|
36
39
|
if (!shared.currentApiMakerCommandsPool) shared.currentApiMakerCommandsPool = new ApiMakerCommandsPool()
|
|
37
40
|
|
|
38
41
|
return shared.currentApiMakerCommandsPool
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
static flush
|
|
44
|
+
static flush() {
|
|
42
45
|
ApiMakerCommandsPool.current().flush()
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
constructor
|
|
48
|
+
constructor() {
|
|
46
49
|
this.flushCount = 0
|
|
47
50
|
this.pool = {}
|
|
48
51
|
this.poolData = {}
|
|
@@ -50,7 +53,9 @@ export default class ApiMakerCommandsPool {
|
|
|
50
53
|
this.globalRequestData = {}
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
addCommand
|
|
56
|
+
addCommand(data) {
|
|
57
|
+
const stack = Error().stack
|
|
58
|
+
|
|
54
59
|
return new Promise((resolve, reject) => {
|
|
55
60
|
const id = this.currentId
|
|
56
61
|
this.currentId += 1
|
|
@@ -59,7 +64,7 @@ export default class ApiMakerCommandsPool {
|
|
|
59
64
|
const commandName = data.command
|
|
60
65
|
const collectionName = data.collectionName
|
|
61
66
|
|
|
62
|
-
this.pool[id] = {resolve, reject}
|
|
67
|
+
this.pool[id] = {resolve, reject, stack}
|
|
63
68
|
|
|
64
69
|
if (!this.poolData[commandType]) this.poolData[commandType] = {}
|
|
65
70
|
if (!this.poolData[commandType][collectionName]) this.poolData[commandType][collectionName] = {}
|
|
@@ -85,17 +90,37 @@ export default class ApiMakerCommandsPool {
|
|
|
85
90
|
})
|
|
86
91
|
}
|
|
87
92
|
|
|
88
|
-
commandsCount
|
|
93
|
+
commandsCount() {
|
|
89
94
|
return Object.keys(this.pool)
|
|
90
95
|
}
|
|
91
96
|
|
|
92
|
-
async
|
|
97
|
+
async sendRequest({commandSubmitData, url}) {
|
|
98
|
+
let response
|
|
99
|
+
|
|
100
|
+
for (let i = 0; i < 3; i++) {
|
|
101
|
+
if (commandSubmitData.getFilesCount() > 0) {
|
|
102
|
+
response = await Api.requestLocal({path: url, method: "POST", rawData: commandSubmitData.getFormData()})
|
|
103
|
+
} else {
|
|
104
|
+
response = await Api.requestLocal({path: url, method: "POST", data: commandSubmitData.getJsonData()})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (response.success === false && response.type == "invalid_authenticity_token") {
|
|
108
|
+
console.log("Invalid authenticity token - try again")
|
|
109
|
+
await SessionStatusUpdater.current().updateSessionStatus()
|
|
110
|
+
continue
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return response
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
throw new Error("Couldnt successfully execute request")
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
flush = async () => {
|
|
93
120
|
if (this.commandsCount() == 0) {
|
|
94
121
|
return
|
|
95
122
|
}
|
|
96
123
|
|
|
97
|
-
this.clearTimeout()
|
|
98
|
-
|
|
99
124
|
const currentPool = this.pool
|
|
100
125
|
const currentPoolData = this.poolData
|
|
101
126
|
|
|
@@ -111,14 +136,7 @@ export default class ApiMakerCommandsPool {
|
|
|
111
136
|
|
|
112
137
|
const commandSubmitData = new CommandSubmitData(submitData)
|
|
113
138
|
const url = "/api_maker/commands"
|
|
114
|
-
|
|
115
|
-
let response
|
|
116
|
-
|
|
117
|
-
if (commandSubmitData.getFilesCount() > 0) {
|
|
118
|
-
response = await Api.requestLocal({path: url, method: "POST", rawData: commandSubmitData.getFormData()})
|
|
119
|
-
} else {
|
|
120
|
-
response = await Api.requestLocal({path: url, method: "POST", data: commandSubmitData.getJsonData()})
|
|
121
|
-
}
|
|
139
|
+
const response = await this.sendRequest({commandSubmitData, url})
|
|
122
140
|
|
|
123
141
|
for (const commandId in response.responses) {
|
|
124
142
|
const commandResponse = response.responses[commandId]
|
|
@@ -137,7 +155,12 @@ export default class ApiMakerCommandsPool {
|
|
|
137
155
|
if (responseType == "success") {
|
|
138
156
|
commandData.resolve(commandResponseData)
|
|
139
157
|
} else if (responseType == "error") {
|
|
140
|
-
|
|
158
|
+
const error = new CustomError("Command error", {response: commandResponseData})
|
|
159
|
+
|
|
160
|
+
error.stack += "\n"
|
|
161
|
+
error.stack += commandData.stack.split("\n").slice(1).join("\n")
|
|
162
|
+
|
|
163
|
+
commandData.reject(error)
|
|
141
164
|
} else if (responseType == "failed") {
|
|
142
165
|
this.handleFailedResponse(commandData, commandResponseData)
|
|
143
166
|
} else {
|
|
@@ -149,7 +172,7 @@ export default class ApiMakerCommandsPool {
|
|
|
149
172
|
}
|
|
150
173
|
}
|
|
151
174
|
|
|
152
|
-
handleFailedResponse
|
|
175
|
+
handleFailedResponse(commandData, commandResponseData) {
|
|
153
176
|
let error
|
|
154
177
|
|
|
155
178
|
if (commandResponseData.error_type == "destroy_error") {
|
|
@@ -160,6 +183,8 @@ export default class ApiMakerCommandsPool {
|
|
|
160
183
|
validationErrors: digg(commandResponseData, "validation_errors")
|
|
161
184
|
})
|
|
162
185
|
error = new ValidationError(validationErrors, {response: commandResponseData})
|
|
186
|
+
|
|
187
|
+
events.emit("onValidationErrors", validationErrors)
|
|
163
188
|
} else {
|
|
164
189
|
let errorMessage
|
|
165
190
|
|
|
@@ -171,13 +196,7 @@ export default class ApiMakerCommandsPool {
|
|
|
171
196
|
commandData.reject(error)
|
|
172
197
|
}
|
|
173
198
|
|
|
174
|
-
|
|
175
|
-
if (this.flushTimeout) {
|
|
176
|
-
clearTimeout(this.flushTimeout)
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
isActive () {
|
|
199
|
+
isActive() {
|
|
181
200
|
if (this.commandsCount() > 0) {
|
|
182
201
|
return true
|
|
183
202
|
}
|
|
@@ -189,8 +208,5 @@ export default class ApiMakerCommandsPool {
|
|
|
189
208
|
return false
|
|
190
209
|
}
|
|
191
210
|
|
|
192
|
-
|
|
193
|
-
this.clearTimeout()
|
|
194
|
-
this.flushTimeout = setTimeout(() => this.flush(), 0)
|
|
195
|
-
}
|
|
211
|
+
flushRunLast = new RunLast(this.flush)
|
|
196
212
|
}
|
package/src/compose.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default function apiMakerCompose(wrappedComponentClass, ...funcs) {
|
|
2
|
+
if (!wrappedComponentClass) throw new Error("No 'wrappedComponentClass' given")
|
|
3
|
+
|
|
4
|
+
let currentComponentClass = wrappedComponentClass
|
|
5
|
+
|
|
6
|
+
for (const func of funcs) {
|
|
7
|
+
currentComponentClass = func(currentComponentClass)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return currentComponentClass
|
|
11
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import inflection from "inflection"
|
|
1
|
+
import * as inflection from "inflection"
|
|
2
2
|
|
|
3
3
|
const accessors = {
|
|
4
4
|
breakPoints: {
|
|
@@ -12,10 +12,14 @@ const accessors = {
|
|
|
12
12
|
],
|
|
13
13
|
required: true
|
|
14
14
|
},
|
|
15
|
+
cableUrl: {require: false},
|
|
15
16
|
currenciesCollection: {required: true},
|
|
16
|
-
history: {required:
|
|
17
|
+
history: {required: true},
|
|
17
18
|
host: {required: false},
|
|
18
19
|
i18n: {required: false},
|
|
20
|
+
linkTo: {required: true},
|
|
21
|
+
modal: {required: false},
|
|
22
|
+
navigation: {required: true},
|
|
19
23
|
routes: {required: false},
|
|
20
24
|
routeDefinitions: {required: false}
|
|
21
25
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as inflection from "inflection"
|
|
2
|
+
|
|
3
|
+
export default function dataSetToAttributes(dataSet) {
|
|
4
|
+
const result = {}
|
|
5
|
+
|
|
6
|
+
for (const key in dataSet) {
|
|
7
|
+
const dasherizedKey = `data-${inflection.dasherize(inflection.underscore(key))}`
|
|
8
|
+
|
|
9
|
+
result[dasherizedKey] = dataSet[key]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return result
|
|
13
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {digg} from "diggerize"
|
|
2
|
-
import inflection from "inflection"
|
|
3
|
-
import modelClassRequire from "./model-class-require
|
|
4
|
-
import ModelsResponseReader from "./models-response-reader
|
|
2
|
+
import * as inflection from "inflection"
|
|
3
|
+
import modelClassRequire from "./model-class-require"
|
|
4
|
+
import ModelsResponseReader from "./models-response-reader"
|
|
5
5
|
import Money from "js-money"
|
|
6
6
|
|
|
7
7
|
export default class ApiMakerDeserializer {
|