amis-core 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/esm/Root.d.ts +0 -46
- package/esm/Root.js +0 -89
- package/esm/RootRenderer.d.ts +0 -27
- package/esm/RootRenderer.js +0 -279
- package/esm/SchemaRenderer.d.ts +0 -37
- package/esm/SchemaRenderer.js +0 -332
- package/esm/Scoped.d.ts +0 -38
- package/esm/Scoped.js +0 -262
- package/esm/WithRootStore.d.ts +0 -719
- package/esm/WithRootStore.js +0 -34
- package/esm/WithStore.d.ts +0 -5
- package/esm/WithStore.js +0 -181
- package/esm/actions/Action.d.ts +0 -40
- package/esm/actions/Action.js +0 -186
- package/esm/actions/AjaxAction.d.ts +0 -27
- package/esm/actions/AjaxAction.js +0 -96
- package/esm/actions/BreakAction.d.ts +0 -15
- package/esm/actions/BreakAction.js +0 -31
- package/esm/actions/BroadcastAction.d.ts +0 -19
- package/esm/actions/BroadcastAction.js +0 -46
- package/esm/actions/CmptAction.d.ts +0 -21
- package/esm/actions/CmptAction.js +0 -66
- package/esm/actions/ContinueAction.d.ts +0 -15
- package/esm/actions/ContinueAction.js +0 -31
- package/esm/actions/CopyAction.d.ts +0 -20
- package/esm/actions/CopyAction.js +0 -39
- package/esm/actions/CustomAction.d.ts +0 -22
- package/esm/actions/CustomAction.js +0 -74
- package/esm/actions/DialogAction.d.ts +0 -60
- package/esm/actions/DialogAction.js +0 -101
- package/esm/actions/DrawerAction.d.ts +0 -33
- package/esm/actions/DrawerAction.js +0 -65
- package/esm/actions/EmailAction.d.ts +0 -23
- package/esm/actions/EmailAction.js +0 -39
- package/esm/actions/LinkAction.d.ts +0 -24
- package/esm/actions/LinkAction.js +0 -43
- package/esm/actions/LoopAction.d.ts +0 -19
- package/esm/actions/LoopAction.js +0 -103
- package/esm/actions/PageAction.d.ts +0 -39
- package/esm/actions/PageAction.js +0 -74
- package/esm/actions/ParallelAction.d.ts +0 -8
- package/esm/actions/ParallelAction.js +0 -36
- package/esm/actions/SwitchAction.d.ts +0 -11
- package/esm/actions/SwitchAction.js +0 -48
- package/esm/actions/ToastAction.d.ts +0 -19
- package/esm/actions/ToastAction.js +0 -31
- package/esm/actions/index.d.ts +0 -20
- package/esm/components/LazyComponent.d.ts +0 -32
- package/esm/components/LazyComponent.js +0 -90
- package/esm/components/Overlay.d.ts +0 -44
- package/esm/components/Overlay.js +0 -255
- package/esm/components/PopOver.d.ts +0 -90
- package/esm/components/PopOver.js +0 -120
- package/esm/env.d.ts +0 -176
- package/esm/env.js +0 -12
- package/esm/envOverwrite.d.ts +0 -4
- package/esm/envOverwrite.js +0 -39
- package/esm/factory.d.ts +0 -85
- package/esm/factory.js +0 -301
- package/esm/index.d.ts +0 -44
- package/esm/index.js +0 -174
- package/esm/locale.d.ts +0 -84
- package/esm/locale.js +0 -117
- package/esm/renderers/Form.d.ts +0 -389
- package/esm/renderers/Form.js +0 -1221
- package/esm/renderers/Item.d.ts +0 -906
- package/esm/renderers/Item.js +0 -863
- package/esm/renderers/Options.d.ts +0 -158
- package/esm/renderers/Options.js +0 -908
- package/esm/renderers/Placeholder.d.ts +0 -6
- package/esm/renderers/Placeholder.js +0 -23
- package/esm/renderers/builtin.d.ts +0 -1
- package/esm/renderers/builtin.js +0 -25
- package/esm/renderers/register.d.ts +0 -6
- package/esm/renderers/register.js +0 -79
- package/esm/renderers/wrapControl.d.ts +0 -437
- package/esm/renderers/wrapControl.js +0 -509
- package/esm/store/app.d.ts +0 -92
- package/esm/store/app.js +0 -189
- package/esm/store/combo.d.ts +0 -10223
- package/esm/store/combo.js +0 -149
- package/esm/store/crud.d.ts +0 -128
- package/esm/store/crud.js +0 -447
- package/esm/store/form.d.ts +0 -4252
- package/esm/store/form.js +0 -650
- package/esm/store/formItem.d.ts +0 -133
- package/esm/store/formItem.js +0 -847
- package/esm/store/iRenderer.d.ts +0 -46
- package/esm/store/iRenderer.js +0 -185
- package/esm/store/index.d.ts +0 -125
- package/esm/store/index.js +0 -90
- package/esm/store/list.d.ts +0 -272
- package/esm/store/list.js +0 -246
- package/esm/store/manager.d.ts +0 -115
- package/esm/store/manager.js +0 -49
- package/esm/store/modal.d.ts +0 -84
- package/esm/store/modal.js +0 -50
- package/esm/store/node.d.ts +0 -22
- package/esm/store/node.js +0 -89
- package/esm/store/pagination.d.ts +0 -58
- package/esm/store/pagination.js +0 -56
- package/esm/store/root.d.ts +0 -85
- package/esm/store/root.js +0 -53
- package/esm/store/service.d.ts +0 -71
- package/esm/store/service.js +0 -411
- package/esm/store/table.d.ts +0 -10085
- package/esm/store/table.js +0 -1136
- package/esm/store/table2.d.ts +0 -474
- package/esm/store/table2.js +0 -560
- package/esm/theme.d.ts +0 -89
- package/esm/theme.js +0 -127
- package/esm/types.d.ts +0 -489
- package/esm/utils/Animation.d.ts +0 -22
- package/esm/utils/Animation.js +0 -285
- package/esm/utils/ColorScale.d.ts +0 -19
- package/esm/utils/ColorScale.js +0 -100
- package/esm/utils/DataSchema.d.ts +0 -25
- package/esm/utils/DataSchema.js +0 -112
- package/esm/utils/DataScope.d.ts +0 -26
- package/esm/utils/DataScope.js +0 -158
- package/esm/utils/RootClose.d.ts +0 -4
- package/esm/utils/RootClose.js +0 -22
- package/esm/utils/SimpleMap.d.ts +0 -8
- package/esm/utils/SimpleMap.js +0 -37
- package/esm/utils/api.d.ts +0 -34
- package/esm/utils/api.js +0 -595
- package/esm/utils/attachmentAdpator.d.ts +0 -8
- package/esm/utils/attachmentAdpator.js +0 -86
- package/esm/utils/autobind.d.ts +0 -7
- package/esm/utils/autobind.js +0 -89
- package/esm/utils/columnsSplit.d.ts +0 -1
- package/esm/utils/columnsSplit.js +0 -42
- package/esm/utils/dataMapping.d.ts +0 -9
- package/esm/utils/dataMapping.js +0 -141
- package/esm/utils/date.d.ts +0 -4
- package/esm/utils/date.js +0 -80
- package/esm/utils/debug.d.ts +0 -29
- package/esm/utils/debug.js +0 -379
- package/esm/utils/decodeEntity.d.ts +0 -5
- package/esm/utils/decodeEntity.js +0 -16
- package/esm/utils/dom.d.ts +0 -13
- package/esm/utils/dom.js +0 -188
- package/esm/utils/errors.d.ts +0 -6
- package/esm/utils/errors.js +0 -19
- package/esm/utils/escapeHtml.d.ts +0 -1
- package/esm/utils/escapeHtml.js +0 -20
- package/esm/utils/filter-schema.d.ts +0 -13
- package/esm/utils/filter-schema.js +0 -68
- package/esm/utils/filter.d.ts +0 -1
- package/esm/utils/filter.js +0 -493
- package/esm/utils/formatDuration.d.ts +0 -1
- package/esm/utils/formatDuration.js +0 -23
- package/esm/utils/formula.d.ts +0 -16
- package/esm/utils/formula.js +0 -219
- package/esm/utils/getVariable.d.ts +0 -3
- package/esm/utils/getVariable.js +0 -25
- package/esm/utils/grammar.d.ts +0 -4
- package/esm/utils/grammar.js +0 -50
- package/esm/utils/handleAction.d.ts +0 -7
- package/esm/utils/handleAction.js +0 -34
- package/esm/utils/helper.d.ts +0 -323
- package/esm/utils/helper.js +0 -1261
- package/esm/utils/highlight.d.ts +0 -1
- package/esm/utils/highlight.js +0 -44
- package/esm/utils/icon.d.ts +0 -16
- package/esm/utils/icon.js +0 -35
- package/esm/utils/image.d.ts +0 -18
- package/esm/utils/image.js +0 -47
- package/esm/utils/index.d.ts +0 -55
- package/esm/utils/isPureVariable.d.ts +0 -1
- package/esm/utils/isPureVariable.js +0 -22
- package/esm/utils/json-schema-2-amis-schema.d.ts +0 -6
- package/esm/utils/json-schema-2-amis-schema.js +0 -56
- package/esm/utils/keyToPath.d.ts +0 -6
- package/esm/utils/keyToPath.js +0 -30
- package/esm/utils/makeSorter.d.ts +0 -1
- package/esm/utils/makeSorter.js +0 -26
- package/esm/utils/normalizeLink.d.ts +0 -1
- package/esm/utils/normalizeLink.js +0 -43
- package/esm/utils/normalizeOptions.d.ts +0 -7
- package/esm/utils/normalizeOptions.js +0 -84
- package/esm/utils/object.d.ts +0 -15
- package/esm/utils/object.js +0 -142
- package/esm/utils/offset.d.ts +0 -15
- package/esm/utils/offset.js +0 -32
- package/esm/utils/offsetParent.d.ts +0 -5
- package/esm/utils/offsetParent.js +0 -23
- package/esm/utils/optionValueCompare.d.ts +0 -3
- package/esm/utils/optionValueCompare.js +0 -25
- package/esm/utils/position.d.ts +0 -26
- package/esm/utils/position.js +0 -54
- package/esm/utils/prettyBytes.d.ts +0 -1
- package/esm/utils/prettyBytes.js +0 -25
- package/esm/utils/renderer-event.d.ts +0 -62
- package/esm/utils/renderer-event.js +0 -206
- package/esm/utils/replaceText.d.ts +0 -3
- package/esm/utils/replaceText.js +0 -38
- package/esm/utils/resize-sensor.d.ts +0 -6
- package/esm/utils/resize-sensor.js +0 -172
- package/esm/utils/resolveVariable.d.ts +0 -1
- package/esm/utils/resolveVariable.js +0 -35
- package/esm/utils/resolveVariableAndFilter.d.ts +0 -1
- package/esm/utils/resolveVariableAndFilter.js +0 -33
- package/esm/utils/scrollPosition.d.ts +0 -16
- package/esm/utils/scrollPosition.js +0 -33
- package/esm/utils/string2regExp.d.ts +0 -1
- package/esm/utils/string2regExp.js +0 -14
- package/esm/utils/stripNumber.d.ts +0 -1
- package/esm/utils/stripNumber.js +0 -16
- package/esm/utils/style.d.ts +0 -10
- package/esm/utils/style.js +0 -58
- package/esm/utils/toNumber.d.ts +0 -7
- package/esm/utils/toNumber.js +0 -18
- package/esm/utils/tokenize.d.ts +0 -1
- package/esm/utils/tokenize.js +0 -29
- package/esm/utils/tpl-builtin.d.ts +0 -18
- package/esm/utils/tpl-builtin.js +0 -59
- package/esm/utils/tpl-lodash.d.ts +0 -4
- package/esm/utils/tpl-lodash.js +0 -62
- package/esm/utils/tpl.d.ts +0 -11
- package/esm/utils/tpl.js +0 -131
- package/esm/utils/uncontrollable.d.ts +0 -4
- package/esm/utils/uncontrollable.js +0 -14
- package/esm/utils/validations.d.ts +0 -39
- package/esm/utils/validations.js +0 -440
- package/lib/Root.d.ts +0 -46
- package/lib/Root.js +0 -102
- package/lib/RootRenderer.d.ts +0 -27
- package/lib/RootRenderer.js +0 -290
- package/lib/SchemaRenderer.d.ts +0 -37
- package/lib/SchemaRenderer.js +0 -342
- package/lib/Scoped.d.ts +0 -38
- package/lib/Scoped.js +0 -274
- package/lib/WithRootStore.d.ts +0 -719
- package/lib/WithRootStore.js +0 -44
- package/lib/WithStore.d.ts +0 -5
- package/lib/WithStore.js +0 -190
- package/lib/actions/Action.d.ts +0 -40
- package/lib/actions/Action.js +0 -197
- package/lib/actions/AjaxAction.d.ts +0 -27
- package/lib/actions/AjaxAction.js +0 -100
- package/lib/actions/BreakAction.d.ts +0 -15
- package/lib/actions/BreakAction.js +0 -35
- package/lib/actions/BroadcastAction.d.ts +0 -19
- package/lib/actions/BroadcastAction.js +0 -50
- package/lib/actions/CmptAction.d.ts +0 -21
- package/lib/actions/CmptAction.js +0 -70
- package/lib/actions/ContinueAction.d.ts +0 -15
- package/lib/actions/ContinueAction.js +0 -35
- package/lib/actions/CopyAction.d.ts +0 -20
- package/lib/actions/CopyAction.js +0 -43
- package/lib/actions/CustomAction.d.ts +0 -22
- package/lib/actions/CustomAction.js +0 -78
- package/lib/actions/DialogAction.d.ts +0 -60
- package/lib/actions/DialogAction.js +0 -108
- package/lib/actions/DrawerAction.d.ts +0 -33
- package/lib/actions/DrawerAction.js +0 -70
- package/lib/actions/EmailAction.d.ts +0 -23
- package/lib/actions/EmailAction.js +0 -48
- package/lib/actions/LinkAction.d.ts +0 -24
- package/lib/actions/LinkAction.js +0 -47
- package/lib/actions/LoopAction.d.ts +0 -19
- package/lib/actions/LoopAction.js +0 -107
- package/lib/actions/PageAction.d.ts +0 -39
- package/lib/actions/PageAction.js +0 -80
- package/lib/actions/ParallelAction.d.ts +0 -8
- package/lib/actions/ParallelAction.js +0 -40
- package/lib/actions/SwitchAction.d.ts +0 -11
- package/lib/actions/SwitchAction.js +0 -52
- package/lib/actions/ToastAction.d.ts +0 -19
- package/lib/actions/ToastAction.js +0 -35
- package/lib/actions/index.d.ts +0 -20
- package/lib/components/LazyComponent.d.ts +0 -32
- package/lib/components/LazyComponent.js +0 -99
- package/lib/components/Overlay.d.ts +0 -44
- package/lib/components/Overlay.js +0 -266
- package/lib/components/PopOver.d.ts +0 -90
- package/lib/components/PopOver.js +0 -129
- package/lib/env.d.ts +0 -176
- package/lib/env.js +0 -20
- package/lib/envOverwrite.d.ts +0 -4
- package/lib/envOverwrite.js +0 -43
- package/lib/factory.d.ts +0 -85
- package/lib/factory.js +0 -324
- package/lib/index.d.ts +0 -44
- package/lib/index.js +0 -460
- package/lib/locale.d.ts +0 -84
- package/lib/locale.js +0 -133
- package/lib/renderers/Form.d.ts +0 -389
- package/lib/renderers/Form.js +0 -1234
- package/lib/renderers/Item.d.ts +0 -906
- package/lib/renderers/Item.js +0 -879
- package/lib/renderers/Options.d.ts +0 -158
- package/lib/renderers/Options.js +0 -920
- package/lib/renderers/Placeholder.d.ts +0 -6
- package/lib/renderers/Placeholder.js +0 -31
- package/lib/renderers/builtin.d.ts +0 -1
- package/lib/renderers/builtin.js +0 -27
- package/lib/renderers/register.d.ts +0 -6
- package/lib/renderers/register.js +0 -83
- package/lib/renderers/wrapControl.d.ts +0 -437
- package/lib/renderers/wrapControl.js +0 -520
- package/lib/store/app.d.ts +0 -92
- package/lib/store/app.js +0 -193
- package/lib/store/combo.d.ts +0 -10223
- package/lib/store/combo.js +0 -154
- package/lib/store/crud.d.ts +0 -128
- package/lib/store/crud.js +0 -455
- package/lib/store/form.d.ts +0 -4252
- package/lib/store/form.js +0 -664
- package/lib/store/formItem.d.ts +0 -133
- package/lib/store/formItem.js +0 -858
- package/lib/store/iRenderer.d.ts +0 -46
- package/lib/store/iRenderer.js +0 -189
- package/lib/store/index.d.ts +0 -125
- package/lib/store/index.js +0 -101
- package/lib/store/list.d.ts +0 -272
- package/lib/store/list.js +0 -256
- package/lib/store/manager.d.ts +0 -115
- package/lib/store/manager.js +0 -56
- package/lib/store/modal.d.ts +0 -84
- package/lib/store/modal.js +0 -54
- package/lib/store/node.d.ts +0 -22
- package/lib/store/node.js +0 -93
- package/lib/store/pagination.d.ts +0 -58
- package/lib/store/pagination.js +0 -60
- package/lib/store/root.d.ts +0 -85
- package/lib/store/root.js +0 -57
- package/lib/store/service.d.ts +0 -71
- package/lib/store/service.js +0 -415
- package/lib/store/table.d.ts +0 -10085
- package/lib/store/table.js +0 -1148
- package/lib/store/table2.d.ts +0 -474
- package/lib/store/table2.js +0 -571
- package/lib/theme.d.ts +0 -89
- package/lib/theme.js +0 -145
- package/lib/types.d.ts +0 -489
- package/lib/utils/Animation.d.ts +0 -22
- package/lib/utils/Animation.js +0 -290
- package/lib/utils/ColorScale.d.ts +0 -19
- package/lib/utils/ColorScale.js +0 -105
- package/lib/utils/DataSchema.d.ts +0 -25
- package/lib/utils/DataSchema.js +0 -116
- package/lib/utils/DataScope.d.ts +0 -26
- package/lib/utils/DataScope.js +0 -162
- package/lib/utils/RootClose.d.ts +0 -4
- package/lib/utils/RootClose.js +0 -30
- package/lib/utils/SimpleMap.d.ts +0 -8
- package/lib/utils/SimpleMap.js +0 -46
- package/lib/utils/api.d.ts +0 -34
- package/lib/utils/api.js +0 -621
- package/lib/utils/attachmentAdpator.d.ts +0 -8
- package/lib/utils/attachmentAdpator.js +0 -91
- package/lib/utils/autobind.d.ts +0 -7
- package/lib/utils/autobind.js +0 -94
- package/lib/utils/columnsSplit.d.ts +0 -1
- package/lib/utils/columnsSplit.js +0 -51
- package/lib/utils/dataMapping.d.ts +0 -9
- package/lib/utils/dataMapping.js +0 -151
- package/lib/utils/date.d.ts +0 -4
- package/lib/utils/date.js +0 -90
- package/lib/utils/debug.d.ts +0 -29
- package/lib/utils/debug.js +0 -392
- package/lib/utils/decodeEntity.d.ts +0 -5
- package/lib/utils/decodeEntity.js +0 -20
- package/lib/utils/dom.d.ts +0 -13
- package/lib/utils/dom.js +0 -199
- package/lib/utils/errors.d.ts +0 -6
- package/lib/utils/errors.js +0 -23
- package/lib/utils/escapeHtml.d.ts +0 -1
- package/lib/utils/escapeHtml.js +0 -24
- package/lib/utils/filter-schema.d.ts +0 -13
- package/lib/utils/filter-schema.js +0 -78
- package/lib/utils/filter.d.ts +0 -1
- package/lib/utils/filter.js +0 -503
- package/lib/utils/formatDuration.d.ts +0 -1
- package/lib/utils/formatDuration.js +0 -27
- package/lib/utils/formula.d.ts +0 -16
- package/lib/utils/formula.js +0 -234
- package/lib/utils/getVariable.d.ts +0 -3
- package/lib/utils/getVariable.js +0 -29
- package/lib/utils/grammar.d.ts +0 -4
- package/lib/utils/grammar.js +0 -54
- package/lib/utils/handleAction.d.ts +0 -7
- package/lib/utils/handleAction.js +0 -39
- package/lib/utils/helper.d.ts +0 -323
- package/lib/utils/helper.js +0 -1361
- package/lib/utils/highlight.d.ts +0 -1
- package/lib/utils/highlight.js +0 -52
- package/lib/utils/icon.d.ts +0 -16
- package/lib/utils/icon.js +0 -43
- package/lib/utils/image.d.ts +0 -18
- package/lib/utils/image.js +0 -56
- package/lib/utils/index.d.ts +0 -55
- package/lib/utils/isPureVariable.d.ts +0 -1
- package/lib/utils/isPureVariable.js +0 -26
- package/lib/utils/json-schema-2-amis-schema.d.ts +0 -6
- package/lib/utils/json-schema-2-amis-schema.js +0 -60
- package/lib/utils/keyToPath.d.ts +0 -6
- package/lib/utils/keyToPath.js +0 -34
- package/lib/utils/makeSorter.d.ts +0 -1
- package/lib/utils/makeSorter.js +0 -30
- package/lib/utils/normalizeLink.d.ts +0 -1
- package/lib/utils/normalizeLink.js +0 -47
- package/lib/utils/normalizeOptions.d.ts +0 -7
- package/lib/utils/normalizeOptions.js +0 -92
- package/lib/utils/object.d.ts +0 -15
- package/lib/utils/object.js +0 -156
- package/lib/utils/offset.d.ts +0 -15
- package/lib/utils/offset.js +0 -37
- package/lib/utils/offsetParent.d.ts +0 -5
- package/lib/utils/offsetParent.js +0 -28
- package/lib/utils/optionValueCompare.d.ts +0 -3
- package/lib/utils/optionValueCompare.js +0 -30
- package/lib/utils/position.d.ts +0 -26
- package/lib/utils/position.js +0 -59
- package/lib/utils/prettyBytes.d.ts +0 -1
- package/lib/utils/prettyBytes.js +0 -29
- package/lib/utils/renderer-event.d.ts +0 -62
- package/lib/utils/renderer-event.js +0 -218
- package/lib/utils/replaceText.d.ts +0 -3
- package/lib/utils/replaceText.js +0 -46
- package/lib/utils/resize-sensor.d.ts +0 -6
- package/lib/utils/resize-sensor.js +0 -177
- package/lib/utils/resolveVariable.d.ts +0 -1
- package/lib/utils/resolveVariable.js +0 -39
- package/lib/utils/resolveVariableAndFilter.d.ts +0 -1
- package/lib/utils/resolveVariableAndFilter.js +0 -37
- package/lib/utils/scrollPosition.d.ts +0 -16
- package/lib/utils/scrollPosition.js +0 -37
- package/lib/utils/string2regExp.d.ts +0 -1
- package/lib/utils/string2regExp.js +0 -18
- package/lib/utils/stripNumber.d.ts +0 -1
- package/lib/utils/stripNumber.js +0 -20
- package/lib/utils/style.d.ts +0 -10
- package/lib/utils/style.js +0 -67
- package/lib/utils/toNumber.d.ts +0 -7
- package/lib/utils/toNumber.js +0 -22
- package/lib/utils/tokenize.d.ts +0 -1
- package/lib/utils/tokenize.js +0 -33
- package/lib/utils/tpl-builtin.d.ts +0 -18
- package/lib/utils/tpl-builtin.js +0 -75
- package/lib/utils/tpl-lodash.d.ts +0 -4
- package/lib/utils/tpl-lodash.js +0 -71
- package/lib/utils/tpl.d.ts +0 -11
- package/lib/utils/tpl.js +0 -140
- package/lib/utils/uncontrollable.d.ts +0 -4
- package/lib/utils/uncontrollable.js +0 -22
- package/lib/utils/validations.d.ts +0 -39
- package/lib/utils/validations.js +0 -455
package/lib/utils/api.js
DELETED
|
@@ -1,621 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* amis-core v2.6.0
|
|
3
|
-
* Copyright 2018-2022 fex
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
9
|
-
|
|
10
|
-
var tslib = require('tslib');
|
|
11
|
-
var omit = require('lodash/omit');
|
|
12
|
-
var amisFormula = require('amis-formula');
|
|
13
|
-
var escapeHtml = require('./escapeHtml.js');
|
|
14
|
-
require('moment');
|
|
15
|
-
var object = require('./object.js');
|
|
16
|
-
var tokenize = require('./tokenize.js');
|
|
17
|
-
var dataMapping = require('./dataMapping.js');
|
|
18
|
-
require('./filter.js');
|
|
19
|
-
var tpl = require('./tpl.js');
|
|
20
|
-
var helper = require('./helper.js');
|
|
21
|
-
var isPlainObject = require('lodash/isPlainObject');
|
|
22
|
-
var debug = require('./debug.js');
|
|
23
|
-
|
|
24
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
25
|
-
|
|
26
|
-
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
27
|
-
var isPlainObject__default = /*#__PURE__*/_interopDefaultLegacy(isPlainObject);
|
|
28
|
-
|
|
29
|
-
var rSchema = /(?:^|raw\:)(get|post|put|delete|patch|options|head|jsonp|js):/i;
|
|
30
|
-
var apiCaches = [];
|
|
31
|
-
var isIE = !!document.documentMode;
|
|
32
|
-
function normalizeApi(api, defaultMethod) {
|
|
33
|
-
if (defaultMethod === void 0) { defaultMethod = 'get'; }
|
|
34
|
-
if (typeof api === 'string') {
|
|
35
|
-
var method = rSchema.test(api) ? RegExp.$1 : '';
|
|
36
|
-
method && (api = api.replace(method + ':', ''));
|
|
37
|
-
api = {
|
|
38
|
-
method: (method || defaultMethod),
|
|
39
|
-
url: api
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
api = tslib.__assign({}, api);
|
|
44
|
-
}
|
|
45
|
-
api.url = typeof api.url === 'string' ? api.url.trim() : api.url;
|
|
46
|
-
return api;
|
|
47
|
-
}
|
|
48
|
-
function buildApi(api, data, options) {
|
|
49
|
-
if (options === void 0) { options = {}; }
|
|
50
|
-
api = normalizeApi(api, options.method);
|
|
51
|
-
var autoAppend = options.autoAppend, ignoreData = options.ignoreData, rest = tslib.__rest(options, ["autoAppend", "ignoreData"]);
|
|
52
|
-
api.config = tslib.__assign({}, rest);
|
|
53
|
-
api.method = (api.method || options.method || 'get').toLowerCase();
|
|
54
|
-
if (api.headers) {
|
|
55
|
-
api.headers = dataMapping.dataMapping(api.headers, data, undefined, false);
|
|
56
|
-
}
|
|
57
|
-
if (api.requestAdaptor && typeof api.requestAdaptor === 'string') {
|
|
58
|
-
api.requestAdaptor = str2function(api.requestAdaptor, 'api');
|
|
59
|
-
}
|
|
60
|
-
if (api.adaptor && typeof api.adaptor === 'string') {
|
|
61
|
-
api.adaptor = str2function(api.adaptor, 'payload', 'response', 'api');
|
|
62
|
-
}
|
|
63
|
-
if (!data) {
|
|
64
|
-
return api;
|
|
65
|
-
}
|
|
66
|
-
else if (data instanceof FormData ||
|
|
67
|
-
data instanceof Blob ||
|
|
68
|
-
data instanceof ArrayBuffer) {
|
|
69
|
-
api.data = data;
|
|
70
|
-
return api;
|
|
71
|
-
}
|
|
72
|
-
var raw = (api.url = api.url || '');
|
|
73
|
-
var ast = undefined;
|
|
74
|
-
try {
|
|
75
|
-
ast = amisFormula.parse(api.url);
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
console.warn("api \u914D\u7F6E\u8BED\u6CD5\u51FA\u9519\uFF1A".concat(e));
|
|
79
|
-
return api;
|
|
80
|
-
}
|
|
81
|
-
var url = ast.body
|
|
82
|
-
.map(function (item, index) {
|
|
83
|
-
return item.type === 'raw' ? item.value : "__expression__".concat(index, "__");
|
|
84
|
-
})
|
|
85
|
-
.join('');
|
|
86
|
-
var idx = url.indexOf('?');
|
|
87
|
-
var replaceExpression = function (fragment, defaultFilter, defVal) {
|
|
88
|
-
if (defaultFilter === void 0) { defaultFilter = 'url_encode'; }
|
|
89
|
-
if (defVal === void 0) { defVal = undefined; }
|
|
90
|
-
return fragment.replace(/__expression__(\d+)__/g, function (_, index) {
|
|
91
|
-
var _a;
|
|
92
|
-
return ((_a = amisFormula.evaluate(ast.body[index], data, {
|
|
93
|
-
defaultFilter: defaultFilter
|
|
94
|
-
})) !== null && _a !== void 0 ? _a : defVal);
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
if (~idx) {
|
|
98
|
-
var hashIdx = url.indexOf('#');
|
|
99
|
-
var params = helper.qsparse(url.substring(idx + 1, ~hashIdx && hashIdx > idx ? hashIdx : undefined));
|
|
100
|
-
// 将里面的表达式运算完
|
|
101
|
-
helper.JSONTraverse(params, function (value, key, host) {
|
|
102
|
-
var _a;
|
|
103
|
-
if (typeof value === 'string' && /^__expression__(\d+)__$/.test(value)) {
|
|
104
|
-
host[key] = (_a = amisFormula.evaluate(ast.body[RegExp.$1].body, data)) !== null && _a !== void 0 ? _a : '';
|
|
105
|
-
}
|
|
106
|
-
else if (typeof value === 'string') {
|
|
107
|
-
// 参数值里面的片段不能 url_encode 了,所以是不处理
|
|
108
|
-
host[key] = replaceExpression(host[key], 'raw', '');
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
var left = replaceExpression(url.substring(0, idx), 'raw', '');
|
|
112
|
-
api.url =
|
|
113
|
-
left +
|
|
114
|
-
(~left.indexOf('?') ? '&' : '?') +
|
|
115
|
-
helper.qsstringify((api.query = dataMapping.dataMapping(params, data, undefined, api.convertKeyToPath))) +
|
|
116
|
-
(~hashIdx && hashIdx > idx
|
|
117
|
-
? replaceExpression(url.substring(hashIdx))
|
|
118
|
-
: '');
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
api.url = replaceExpression(url, 'raw', '');
|
|
122
|
-
}
|
|
123
|
-
if (ignoreData) {
|
|
124
|
-
return api;
|
|
125
|
-
}
|
|
126
|
-
if (api.data) {
|
|
127
|
-
api.body = api.data = dataMapping.dataMapping(api.data, data, undefined, api.convertKeyToPath);
|
|
128
|
-
}
|
|
129
|
-
else if (api.method === 'post' ||
|
|
130
|
-
api.method === 'put' ||
|
|
131
|
-
api.method === 'patch') {
|
|
132
|
-
api.body = api.data = data;
|
|
133
|
-
}
|
|
134
|
-
// get 类请求,把 data 附带到 url 上。
|
|
135
|
-
if (api.method === 'get' || api.method === 'jsonp' || api.method === 'js') {
|
|
136
|
-
if (!api.data &&
|
|
137
|
-
((!~raw.indexOf('$') && autoAppend) || api.forceAppendDataToQuery)) {
|
|
138
|
-
api.query = api.data = data;
|
|
139
|
-
}
|
|
140
|
-
else if (api.attachDataToQuery === false &&
|
|
141
|
-
api.data &&
|
|
142
|
-
((!~raw.indexOf('$') && autoAppend) || api.forceAppendDataToQuery)) {
|
|
143
|
-
var idx_1 = api.url.indexOf('?');
|
|
144
|
-
if (~idx_1) {
|
|
145
|
-
var params = (api.query = tslib.__assign(tslib.__assign({}, helper.qsparse(api.url.substring(idx_1 + 1))), data));
|
|
146
|
-
api.url = api.url.substring(0, idx_1) + '?' + helper.qsstringify(params);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
api.query = data;
|
|
150
|
-
var query = helper.qsstringify(data);
|
|
151
|
-
if (query) {
|
|
152
|
-
api.url = "".concat(api.url, "?").concat(query);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
if (api.data && api.attachDataToQuery !== false) {
|
|
157
|
-
var idx_2 = api.url.indexOf('?');
|
|
158
|
-
if (~idx_2) {
|
|
159
|
-
var params = (api.query = tslib.__assign(tslib.__assign({}, helper.qsparse(api.url.substring(idx_2 + 1))), api.data));
|
|
160
|
-
api.url = api.url.substring(0, idx_2) + '?' + helper.qsstringify(params);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
api.query = api.data;
|
|
164
|
-
var query = helper.qsstringify(api.data);
|
|
165
|
-
if (query) {
|
|
166
|
-
api.url = "".concat(api.url, "?").concat(query);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
delete api.data;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (api.graphql) {
|
|
173
|
-
if (api.method === 'get') {
|
|
174
|
-
api.query = api.data = tslib.__assign(tslib.__assign({}, api.query), { query: api.graphql });
|
|
175
|
-
}
|
|
176
|
-
else if (api.method === 'post' ||
|
|
177
|
-
api.method === 'put' ||
|
|
178
|
-
api.method === 'patch') {
|
|
179
|
-
api.body = api.data = {
|
|
180
|
-
query: api.graphql,
|
|
181
|
-
operationName: api.operationName,
|
|
182
|
-
variables: object.cloneObject(api.data)
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return api;
|
|
187
|
-
}
|
|
188
|
-
function str2function(contents) {
|
|
189
|
-
var args = [];
|
|
190
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
191
|
-
args[_i - 1] = arguments[_i];
|
|
192
|
-
}
|
|
193
|
-
try {
|
|
194
|
-
var fn = new (Function.bind.apply(Function, tslib.__spreadArray(tslib.__spreadArray([void 0], args, false), [contents], false)))();
|
|
195
|
-
return fn;
|
|
196
|
-
}
|
|
197
|
-
catch (e) {
|
|
198
|
-
console.warn(e);
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
var AsyncFunction = Object.getPrototypeOf(function () {
|
|
203
|
-
return tslib.__awaiter(this, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
|
|
204
|
-
return [2 /*return*/];
|
|
205
|
-
}); });
|
|
206
|
-
}).constructor;
|
|
207
|
-
function str2AsyncFunction(contents) {
|
|
208
|
-
var args = [];
|
|
209
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
210
|
-
args[_i - 1] = arguments[_i];
|
|
211
|
-
}
|
|
212
|
-
try {
|
|
213
|
-
var fn = new (AsyncFunction.bind.apply(AsyncFunction, tslib.__spreadArray(tslib.__spreadArray([void 0], args, false), [contents], false)))();
|
|
214
|
-
return fn;
|
|
215
|
-
}
|
|
216
|
-
catch (e) {
|
|
217
|
-
console.warn(e);
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
function responseAdaptor(ret, api) {
|
|
222
|
-
var data = ret.data;
|
|
223
|
-
var hasStatusField = true;
|
|
224
|
-
if (!data) {
|
|
225
|
-
throw new Error('Response is empty');
|
|
226
|
-
}
|
|
227
|
-
// 返回内容是 string,说明 content-type 不是 json,这时可能是返回了纯文本或 html
|
|
228
|
-
if (typeof data === 'string') {
|
|
229
|
-
var contentType = ret.headers['content-type'] || '';
|
|
230
|
-
// 如果是文本类型就尝试解析一下
|
|
231
|
-
if (ret.headers &&
|
|
232
|
-
contentType.startsWith('text/') &&
|
|
233
|
-
!contentType.includes('markdown')) {
|
|
234
|
-
try {
|
|
235
|
-
data = JSON.parse(data);
|
|
236
|
-
if (typeof data === 'undefined') {
|
|
237
|
-
throw new Error('Response should be JSON');
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
catch (e) {
|
|
241
|
-
var responseBrief = typeof data === 'string'
|
|
242
|
-
? escapeHtml.escapeHtml(data.substring(0, 100))
|
|
243
|
-
: '';
|
|
244
|
-
throw new Error("Response should be JSON\n ".concat(responseBrief));
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
if (api.responseType === 'blob') {
|
|
249
|
-
throw new Error('Should have "Content-Disposition" in Header');
|
|
250
|
-
}
|
|
251
|
-
else if (!contentType.includes('markdown')) {
|
|
252
|
-
throw new Error("Content is wrong content-type:\"".concat(contentType, "\" content: ").concat(escapeHtml.escapeHtml(data.substring(0, 100))));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
// 兼容几种常见写法
|
|
257
|
-
if (data.hasOwnProperty('errorCode')) {
|
|
258
|
-
// 阿里 Java 规范
|
|
259
|
-
data.status = data.errorCode;
|
|
260
|
-
data.msg = data.errorMessage || data.errorMsg;
|
|
261
|
-
}
|
|
262
|
-
else if (data.hasOwnProperty('errno')) {
|
|
263
|
-
data.status = data.errno;
|
|
264
|
-
data.msg = data.errmsg || data.errstr || data.msg;
|
|
265
|
-
}
|
|
266
|
-
else if (data.hasOwnProperty('no')) {
|
|
267
|
-
data.status = data.no;
|
|
268
|
-
data.msg = data.error || data.msg;
|
|
269
|
-
}
|
|
270
|
-
else if (data.hasOwnProperty('error')) {
|
|
271
|
-
// Google JSON guide
|
|
272
|
-
// https://google.github.io/styleguide/jsoncstyleguide.xml#error
|
|
273
|
-
if (typeof data.error === 'object' && data.error.hasOwnProperty('code')) {
|
|
274
|
-
data.status = data.error.code;
|
|
275
|
-
data.msg = data.error.message;
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
data.status = data.error;
|
|
279
|
-
data.msg = data.errmsg || data.msg;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
if (!data.hasOwnProperty('status')) {
|
|
283
|
-
hasStatusField = false;
|
|
284
|
-
}
|
|
285
|
-
var payload = {
|
|
286
|
-
ok: hasStatusField === false || data.status == 0,
|
|
287
|
-
status: hasStatusField === false ? 0 : data.status,
|
|
288
|
-
msg: data.msg || data.message,
|
|
289
|
-
defaultMsg: data.defaultMsg,
|
|
290
|
-
msgTimeout: data.msgTimeout,
|
|
291
|
-
data: !data.data && !hasStatusField ? data : data.data // 兼容直接返回数据的情况
|
|
292
|
-
};
|
|
293
|
-
// 兼容返回 schema 的情况,用于 app 模式
|
|
294
|
-
if (data && data.type) {
|
|
295
|
-
payload.data = data;
|
|
296
|
-
}
|
|
297
|
-
if (payload.status == 422) {
|
|
298
|
-
payload.errors = data.errors;
|
|
299
|
-
}
|
|
300
|
-
debug.debug('api', 'response', payload);
|
|
301
|
-
if (payload.ok && api.responseData) {
|
|
302
|
-
debug.debug('api', 'before dataMapping', payload.data);
|
|
303
|
-
var responseData = dataMapping.dataMapping(api.responseData, object.createObject({ api: api }, (Array.isArray(payload.data)
|
|
304
|
-
? {
|
|
305
|
-
items: payload.data
|
|
306
|
-
}
|
|
307
|
-
: payload.data) || {}), undefined, api.convertKeyToPath);
|
|
308
|
-
debug.debug('api', 'after dataMapping', responseData);
|
|
309
|
-
payload.data = responseData;
|
|
310
|
-
}
|
|
311
|
-
return payload;
|
|
312
|
-
}
|
|
313
|
-
function wrapFetcher(fn, tracker) {
|
|
314
|
-
// 避免重复处理
|
|
315
|
-
if (fn._wrappedFetcher) {
|
|
316
|
-
return fn;
|
|
317
|
-
}
|
|
318
|
-
var wrappedFetcher = function (api, data, options) {
|
|
319
|
-
var _a, _b, _c;
|
|
320
|
-
api = buildApi(api, data, options);
|
|
321
|
-
if (api.requestAdaptor) {
|
|
322
|
-
debug.debug('api', 'before requestAdaptor', api);
|
|
323
|
-
api = api.requestAdaptor(api) || api;
|
|
324
|
-
debug.debug('api', 'after requestAdaptor', api);
|
|
325
|
-
}
|
|
326
|
-
if (api.data && (helper.hasFile(api.data) || api.dataType === 'form-data')) {
|
|
327
|
-
api.data =
|
|
328
|
-
api.data instanceof FormData
|
|
329
|
-
? api.data
|
|
330
|
-
: helper.object2formData(api.data, api.qsOptions);
|
|
331
|
-
}
|
|
332
|
-
else if (api.data &&
|
|
333
|
-
typeof api.data !== 'string' &&
|
|
334
|
-
api.dataType === 'form') {
|
|
335
|
-
api.data = helper.qsstringify(api.data, api.qsOptions);
|
|
336
|
-
api.headers = api.headers || (api.headers = {});
|
|
337
|
-
api.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
338
|
-
}
|
|
339
|
-
else if (api.data &&
|
|
340
|
-
typeof api.data !== 'string' &&
|
|
341
|
-
api.dataType === 'json') {
|
|
342
|
-
api.data = JSON.stringify(api.data);
|
|
343
|
-
api.headers = api.headers || (api.headers = {});
|
|
344
|
-
api.headers['Content-Type'] = 'application/json';
|
|
345
|
-
}
|
|
346
|
-
if (!isValidApi(api.url)) {
|
|
347
|
-
debug.warning('api', 'invalid api url', api);
|
|
348
|
-
return Promise.resolve();
|
|
349
|
-
}
|
|
350
|
-
debug.debug('api', 'request api', api);
|
|
351
|
-
tracker === null || tracker === void 0 ? void 0 : tracker({ eventType: 'api', eventData: omit__default["default"](api, ['config', 'data', 'body']) }, api.data);
|
|
352
|
-
if (((_a = api.method) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === 'jsonp') {
|
|
353
|
-
return wrapAdaptor(jsonpFetcher(api), api);
|
|
354
|
-
}
|
|
355
|
-
if (((_b = api.method) === null || _b === void 0 ? void 0 : _b.toLocaleLowerCase()) === 'js') {
|
|
356
|
-
return wrapAdaptor(jsFetcher(fn, api), api);
|
|
357
|
-
}
|
|
358
|
-
if (typeof api.cache === 'number' && api.cache > 0) {
|
|
359
|
-
var apiCache = getApiCache(api);
|
|
360
|
-
return wrapAdaptor(apiCache
|
|
361
|
-
? apiCache.cachedPromise
|
|
362
|
-
: setApiCache(api, fn(api)), api);
|
|
363
|
-
}
|
|
364
|
-
// IE 下 get 请求会被缓存,所以自动加个时间戳
|
|
365
|
-
if (isIE && api && ((_c = api.method) === null || _c === void 0 ? void 0 : _c.toLocaleLowerCase()) === 'get') {
|
|
366
|
-
var timeStamp = "_t=".concat(Date.now());
|
|
367
|
-
if (api.url.indexOf('?') === -1) {
|
|
368
|
-
api.url = api.url + "?".concat(timeStamp);
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
api.url = api.url + "&".concat(timeStamp);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
return wrapAdaptor(fn(api), api);
|
|
375
|
-
};
|
|
376
|
-
wrappedFetcher._wrappedFetcher = true;
|
|
377
|
-
return wrappedFetcher;
|
|
378
|
-
}
|
|
379
|
-
function wrapAdaptor(promise, api) {
|
|
380
|
-
var _this = this;
|
|
381
|
-
var adaptor = api.adaptor;
|
|
382
|
-
return adaptor
|
|
383
|
-
? promise
|
|
384
|
-
.then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
385
|
-
var result;
|
|
386
|
-
return tslib.__generator(this, function (_a) {
|
|
387
|
-
switch (_a.label) {
|
|
388
|
-
case 0:
|
|
389
|
-
debug.debug('api', 'before adaptor data', response.data);
|
|
390
|
-
result = adaptor(response.data, response, api);
|
|
391
|
-
if (!(result === null || result === void 0 ? void 0 : result.then)) return [3 /*break*/, 2];
|
|
392
|
-
return [4 /*yield*/, result];
|
|
393
|
-
case 1:
|
|
394
|
-
result = _a.sent();
|
|
395
|
-
_a.label = 2;
|
|
396
|
-
case 2:
|
|
397
|
-
debug.debug('api', 'after adaptor data', result);
|
|
398
|
-
return [2 /*return*/, tslib.__assign(tslib.__assign({}, response), { data: result })];
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
}); })
|
|
402
|
-
.then(function (ret) { return responseAdaptor(ret, api); })
|
|
403
|
-
: promise.then(function (ret) { return responseAdaptor(ret, api); });
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* 请求远程 js 文件然后 new Function 执行,用于 schemaApi 支持 JavaScript
|
|
407
|
-
* @param api
|
|
408
|
-
* @returns
|
|
409
|
-
*/
|
|
410
|
-
function jsFetcher(fetcher, api) {
|
|
411
|
-
return new Promise(function (resolve, reject) {
|
|
412
|
-
// 大概也不会有人用 post
|
|
413
|
-
api.method = 'get';
|
|
414
|
-
fetcher(api).then(function (response) {
|
|
415
|
-
if (typeof response.data === 'string') {
|
|
416
|
-
var result = new Function('api', response.data)(api);
|
|
417
|
-
resolve({
|
|
418
|
-
status: 200,
|
|
419
|
-
headers: {},
|
|
420
|
-
data: {
|
|
421
|
-
status: 0,
|
|
422
|
-
msg: '',
|
|
423
|
-
data: result
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
else {
|
|
428
|
-
reject('must return string: ' + response.data);
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
function jsonpFetcher(api) {
|
|
434
|
-
return new Promise(function (resolve, reject) {
|
|
435
|
-
var _a;
|
|
436
|
-
var script = document.createElement('script');
|
|
437
|
-
var src = api.url;
|
|
438
|
-
script.async = true;
|
|
439
|
-
function remove() {
|
|
440
|
-
if (script) {
|
|
441
|
-
// @ts-ignore
|
|
442
|
-
script.onload = script.onreadystatechange = script.onerror = null;
|
|
443
|
-
if (script.parentNode) {
|
|
444
|
-
script.parentNode.removeChild(script);
|
|
445
|
-
}
|
|
446
|
-
script = null;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
var jsonp = ((_a = api.query) === null || _a === void 0 ? void 0 : _a.callback) || 'axiosJsonpCallback' + helper.uuid();
|
|
450
|
-
var old = window[jsonp];
|
|
451
|
-
window[jsonp] = function (responseData) {
|
|
452
|
-
window[jsonp] = old;
|
|
453
|
-
var response = {
|
|
454
|
-
data: responseData,
|
|
455
|
-
status: 200,
|
|
456
|
-
headers: {}
|
|
457
|
-
};
|
|
458
|
-
resolve(response);
|
|
459
|
-
};
|
|
460
|
-
var additionalParams = {
|
|
461
|
-
_: new Date().getTime(),
|
|
462
|
-
_callback: jsonp
|
|
463
|
-
};
|
|
464
|
-
src += (src.indexOf('?') >= 0 ? '&' : '?') + helper.qsstringify(additionalParams);
|
|
465
|
-
// @ts-ignore IE 为script.onreadystatechange
|
|
466
|
-
script.onload = script.onreadystatechange = function () {
|
|
467
|
-
// @ts-ignore
|
|
468
|
-
if (!script.readyState || /loaded|complete/.test(script.readyState)) {
|
|
469
|
-
remove();
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
script.onerror = function () {
|
|
473
|
-
remove();
|
|
474
|
-
var errResponse = {
|
|
475
|
-
status: 0,
|
|
476
|
-
headers: {}
|
|
477
|
-
};
|
|
478
|
-
reject(errResponse);
|
|
479
|
-
};
|
|
480
|
-
script.src = src;
|
|
481
|
-
document.head.appendChild(script);
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
// 避免在 isApiOutdated 中修改,减少影响
|
|
485
|
-
function isApiOutdatedWithData(prevApi, nextApi, prevData, nextData) {
|
|
486
|
-
if (!nextApi) {
|
|
487
|
-
return false;
|
|
488
|
-
}
|
|
489
|
-
else if (!prevApi) {
|
|
490
|
-
return true;
|
|
491
|
-
}
|
|
492
|
-
return helper.isObjectShallowModified(buildApi(normalizeApi(prevApi), prevData), buildApi(normalizeApi(nextApi), nextData));
|
|
493
|
-
}
|
|
494
|
-
function isApiOutdated(prevApi, nextApi, prevData, nextData) {
|
|
495
|
-
var _a;
|
|
496
|
-
if (!nextApi) {
|
|
497
|
-
return false;
|
|
498
|
-
}
|
|
499
|
-
nextApi = normalizeApi(nextApi);
|
|
500
|
-
if (nextApi.autoRefresh === false) {
|
|
501
|
-
return false;
|
|
502
|
-
}
|
|
503
|
-
var trackExpression = (_a = nextApi.trackExpression) !== null && _a !== void 0 ? _a : nextApi.url;
|
|
504
|
-
if (typeof trackExpression !== 'string' || !~trackExpression.indexOf('$')) {
|
|
505
|
-
return false;
|
|
506
|
-
}
|
|
507
|
-
var isModified = false;
|
|
508
|
-
if (prevApi) {
|
|
509
|
-
prevApi = normalizeApi(prevApi);
|
|
510
|
-
if (nextApi.trackExpression || prevApi.trackExpression) {
|
|
511
|
-
isModified =
|
|
512
|
-
tokenize.tokenize(prevApi.trackExpression || '', prevData) !==
|
|
513
|
-
tokenize.tokenize(nextApi.trackExpression || '', nextData);
|
|
514
|
-
}
|
|
515
|
-
else {
|
|
516
|
-
prevApi = buildApi(prevApi, prevData, {
|
|
517
|
-
ignoreData: true
|
|
518
|
-
});
|
|
519
|
-
nextApi = buildApi(nextApi, nextData, {
|
|
520
|
-
ignoreData: true
|
|
521
|
-
});
|
|
522
|
-
isModified = prevApi.url !== nextApi.url;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
else {
|
|
526
|
-
isModified = true;
|
|
527
|
-
}
|
|
528
|
-
return !!(isModified &&
|
|
529
|
-
isValidApi(nextApi.url) &&
|
|
530
|
-
(!nextApi.sendOn || tpl.evalExpression(nextApi.sendOn, nextData)));
|
|
531
|
-
}
|
|
532
|
-
function isValidApi(api) {
|
|
533
|
-
return (api &&
|
|
534
|
-
/^(?:(https?|wss?|taf):\/\/[^\/]+)?(\/?[^\s\/\?]*){1,}(\?.*)?$/.test(api));
|
|
535
|
-
}
|
|
536
|
-
function isEffectiveApi(api, data, initFetch, initFetchOn) {
|
|
537
|
-
if (!api) {
|
|
538
|
-
return false;
|
|
539
|
-
}
|
|
540
|
-
if (initFetch === false) {
|
|
541
|
-
return false;
|
|
542
|
-
}
|
|
543
|
-
if (initFetchOn && data && !tpl.evalExpression(initFetchOn, data)) {
|
|
544
|
-
return false;
|
|
545
|
-
}
|
|
546
|
-
if (typeof api === 'string' && api.length) {
|
|
547
|
-
return true;
|
|
548
|
-
}
|
|
549
|
-
else if (object.isObject(api) && api.url) {
|
|
550
|
-
if (api.sendOn &&
|
|
551
|
-
data &&
|
|
552
|
-
!tpl.evalExpression(api.sendOn, data)) {
|
|
553
|
-
return false;
|
|
554
|
-
}
|
|
555
|
-
return true;
|
|
556
|
-
}
|
|
557
|
-
return false;
|
|
558
|
-
}
|
|
559
|
-
function isSameApi(apiA, apiB) {
|
|
560
|
-
return (apiA.method === apiB.method &&
|
|
561
|
-
apiA.url === apiB.url &&
|
|
562
|
-
!helper.isObjectShallowModified(apiA.data, apiB.data, false));
|
|
563
|
-
}
|
|
564
|
-
function getApiCache(api) {
|
|
565
|
-
// 清理过期cache
|
|
566
|
-
var now = Date.now();
|
|
567
|
-
var result;
|
|
568
|
-
for (var idx = 0, len = apiCaches.length; idx < len; idx++) {
|
|
569
|
-
var apiCache = apiCaches[idx];
|
|
570
|
-
if (now - apiCache.requestTime > apiCache.cache) {
|
|
571
|
-
apiCaches.splice(idx, 1);
|
|
572
|
-
len--;
|
|
573
|
-
idx--;
|
|
574
|
-
continue;
|
|
575
|
-
}
|
|
576
|
-
if (isSameApi(api, apiCache)) {
|
|
577
|
-
result = apiCache;
|
|
578
|
-
break;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
return result;
|
|
582
|
-
}
|
|
583
|
-
function setApiCache(api, promise) {
|
|
584
|
-
apiCaches.push(tslib.__assign(tslib.__assign({}, api), { cachedPromise: promise, requestTime: Date.now() }));
|
|
585
|
-
return promise;
|
|
586
|
-
}
|
|
587
|
-
function clearApiCache() {
|
|
588
|
-
apiCaches.splice(0, apiCaches.length);
|
|
589
|
-
}
|
|
590
|
-
function normalizeApiResponseData(data) {
|
|
591
|
-
var _a;
|
|
592
|
-
if (typeof data === 'undefined') {
|
|
593
|
-
data = {};
|
|
594
|
-
}
|
|
595
|
-
else if (!isPlainObject__default["default"](data)) {
|
|
596
|
-
data = (_a = {},
|
|
597
|
-
_a[Array.isArray(data) ? 'items' : 'result'] = data,
|
|
598
|
-
_a);
|
|
599
|
-
}
|
|
600
|
-
return data;
|
|
601
|
-
}
|
|
602
|
-
// window.apiCaches = apiCaches;
|
|
603
|
-
|
|
604
|
-
exports.buildApi = buildApi;
|
|
605
|
-
exports.clearApiCache = clearApiCache;
|
|
606
|
-
exports.getApiCache = getApiCache;
|
|
607
|
-
exports.isApiOutdated = isApiOutdated;
|
|
608
|
-
exports.isApiOutdatedWithData = isApiOutdatedWithData;
|
|
609
|
-
exports.isEffectiveApi = isEffectiveApi;
|
|
610
|
-
exports.isSameApi = isSameApi;
|
|
611
|
-
exports.isValidApi = isValidApi;
|
|
612
|
-
exports.jsFetcher = jsFetcher;
|
|
613
|
-
exports.jsonpFetcher = jsonpFetcher;
|
|
614
|
-
exports.normalizeApi = normalizeApi;
|
|
615
|
-
exports.normalizeApiResponseData = normalizeApiResponseData;
|
|
616
|
-
exports.responseAdaptor = responseAdaptor;
|
|
617
|
-
exports.setApiCache = setApiCache;
|
|
618
|
-
exports.str2AsyncFunction = str2AsyncFunction;
|
|
619
|
-
exports.str2function = str2function;
|
|
620
|
-
exports.wrapAdaptor = wrapAdaptor;
|
|
621
|
-
exports.wrapFetcher = wrapFetcher;
|