@ramathibodi/nuxt-commons 0.1.45 → 0.1.46
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/dist/module.d.mts +2 -1
- package/dist/module.d.ts +2 -1
- package/dist/module.json +2 -2
- package/dist/runtime/components/ExportCSV.vue +3 -1
- package/dist/runtime/components/ImportCSV.vue +11 -1
- package/dist/runtime/components/form/Dialog.vue +48 -22
- package/dist/runtime/components/form/Table.vue +21 -0
- package/dist/runtime/components/master/Autocomplete.vue +5 -0
- package/dist/runtime/components/master/label.vue +4 -0
- package/dist/runtime/components/model/Autocomplete.vue +1 -1
- package/dist/runtime/components/model/Table.vue +19 -0
- package/dist/runtime/components/model/label.vue +3 -3
- package/dist/runtime/composables/api.d.ts +5 -4
- package/dist/runtime/composables/api.js +38 -9
- package/dist/runtime/composables/graphql.d.ts +1 -1
- package/dist/runtime/composables/graphql.js +3 -3
- package/dist/runtime/composables/graphqlModel.d.ts +6 -6
- package/dist/runtime/composables/graphqlModel.js +2 -0
- package/dist/runtime/composables/graphqlModelItem.d.ts +4 -4
- package/dist/runtime/composables/graphqlModelOperation.d.ts +6 -6
- package/dist/runtime/composables/graphqlOperation.d.ts +1 -1
- package/dist/runtime/types/formDialog.d.ts +1 -0
- package/dist/runtime/types/graphqlOperation.d.ts +1 -1
- package/dist/runtime/utils/datetime.d.ts +36 -161
- package/dist/runtime/utils/hash.d.ts +1 -0
- package/dist/runtime/utils/hash.js +7 -0
- package/dist/runtime/utils/object.d.ts +1 -0
- package/dist/runtime/utils/object.js +25 -0
- package/dist/types.d.mts +7 -1
- package/dist/types.d.ts +7 -1
- package/package.json +40 -38
- package/templates/.codegen/plugin-schema-object.js +2 -2
package/dist/module.d.mts
CHANGED
package/dist/module.d.ts
CHANGED
package/dist/module.json
CHANGED
|
@@ -8,11 +8,13 @@ interface ExportButtonProps extends /* @vue-ignore */ InstanceType<typeof VBtn['
|
|
|
8
8
|
fileName?: string
|
|
9
9
|
sheetName?: string
|
|
10
10
|
modelValue?: object[]
|
|
11
|
+
stringFields?: Array<string>
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
const props = withDefaults(defineProps<ExportButtonProps>(), {
|
|
14
15
|
fileName: 'download',
|
|
15
16
|
sheetName: 'Sheet1',
|
|
17
|
+
stringFields: ()=>[],
|
|
16
18
|
})
|
|
17
19
|
|
|
18
20
|
const alert = useAlert()
|
|
@@ -63,7 +65,7 @@ function flattenObject(obj: any, parentKey = '', separator = '.') {
|
|
|
63
65
|
const newKey = parentKey ? `${parentKey}${separator}${key}` : key
|
|
64
66
|
const value = obj[key]
|
|
65
67
|
|
|
66
|
-
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
68
|
+
if (value && typeof value === 'object' && !Array.isArray(value) && !props.stringFields.includes(newKey)) {
|
|
67
69
|
Object.assign(acc, flattenObject(value, newKey, separator))
|
|
68
70
|
} else {
|
|
69
71
|
acc[newKey] = typeof value === 'object' ? JSON.stringify(value) : value
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
import * as XLSX from 'xlsx'
|
|
3
3
|
import { ref } from 'vue'
|
|
4
4
|
import { useAlert } from '../composables/alert'
|
|
5
|
+
import { VBtn } from 'vuetify/components/VBtn'
|
|
6
|
+
|
|
7
|
+
interface ImportButtonProps extends /* @vue-ignore */ InstanceType<typeof VBtn['$props']> {
|
|
8
|
+
stringFields?: Array<string>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<ImportButtonProps>(), {
|
|
12
|
+
stringFields: ()=>[],
|
|
13
|
+
})
|
|
5
14
|
|
|
6
15
|
const alert = useAlert()
|
|
7
16
|
const emit = defineEmits<{
|
|
@@ -59,7 +68,8 @@ const parseAndAggregateColumns = (items: any[]) => {
|
|
|
59
68
|
assignNestedValue(aggregatedItem[rootKey], subKeys, parseIfJson(item[key]))
|
|
60
69
|
} else {
|
|
61
70
|
// Directly assign root-level properties
|
|
62
|
-
aggregatedItem[key] =
|
|
71
|
+
if (props.stringFields.includes(key)) aggregatedItem[key] = item[key]
|
|
72
|
+
else aggregatedItem[key] = parseIfJson(item[key])
|
|
63
73
|
}
|
|
64
74
|
}
|
|
65
75
|
|
|
@@ -11,24 +11,30 @@ interface Props {
|
|
|
11
11
|
formData?: object
|
|
12
12
|
saveCaption?: string
|
|
13
13
|
cancelCaption?: string
|
|
14
|
+
closeCaption?: string
|
|
15
|
+
saveAndStay?: boolean
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
const props = withDefaults(defineProps<Props>(), {
|
|
17
19
|
saveCaption: 'บันทึก',
|
|
18
20
|
cancelCaption: 'ยกเลิก',
|
|
21
|
+
closeCaption: 'ปิด',
|
|
22
|
+
saveAndStay: false,
|
|
19
23
|
})
|
|
20
24
|
|
|
21
25
|
const isShowing = defineModel<boolean>({ default: false })
|
|
22
26
|
const isSaving = ref<boolean>(false)
|
|
27
|
+
const isSavedAndStay = ref<boolean>(false)
|
|
23
28
|
const formPadRef = ref()
|
|
24
29
|
const formData = ref<object>({})
|
|
30
|
+
const formDataOriginalValue = ref<object>()
|
|
25
31
|
|
|
26
32
|
const emit = defineEmits(['create', 'update'])
|
|
27
33
|
|
|
28
34
|
function save() {
|
|
29
35
|
if (formPadRef.value.isValid) {
|
|
30
36
|
isSaving.value = true
|
|
31
|
-
emit((isCreating.value) ? 'create' : 'update', cloneDeep(formData.value), callback)
|
|
37
|
+
emit((isCreating.value) ? 'create' : 'update', cloneDeep(formData.value), (props.saveAndStay) ? stayCallback : callback)
|
|
32
38
|
}
|
|
33
39
|
}
|
|
34
40
|
|
|
@@ -46,12 +52,26 @@ const callback: FormDialogCallback = {
|
|
|
46
52
|
},
|
|
47
53
|
}
|
|
48
54
|
|
|
55
|
+
const stayCallback: FormDialogCallback = {
|
|
56
|
+
done: function () {
|
|
57
|
+
isSaving.value = false
|
|
58
|
+
isSavedAndStay.value = true
|
|
59
|
+
},
|
|
60
|
+
error: function () {
|
|
61
|
+
isSaving.value = false
|
|
62
|
+
},
|
|
63
|
+
setData: function (item: object) {
|
|
64
|
+
formData.value = cloneDeep(item)
|
|
65
|
+
formDataOriginalValue.value = cloneDeep(item)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
49
69
|
const isDataChange = computed(() => {
|
|
50
|
-
return !((isCreating.value) ? isEqual(formData.value, createOriginalValue.value) : isEqual(formData.value,
|
|
70
|
+
return !((isCreating.value) ? isEqual(formData.value, createOriginalValue.value) : isEqual(formData.value, formDataOriginalValue.value))
|
|
51
71
|
})
|
|
52
72
|
|
|
53
73
|
const isCreating = computed(() => {
|
|
54
|
-
return !props.formData
|
|
74
|
+
return !props.formData && !isSavedAndStay.value
|
|
55
75
|
})
|
|
56
76
|
|
|
57
77
|
const createOriginalValue = computed(() => {
|
|
@@ -61,12 +81,16 @@ const createOriginalValue = computed(() => {
|
|
|
61
81
|
const loadFormData = () => {
|
|
62
82
|
if (props.formData) {
|
|
63
83
|
formData.value = cloneDeep(props.formData)
|
|
84
|
+
formDataOriginalValue.value = cloneDeep(props.formData)
|
|
64
85
|
}
|
|
65
86
|
else {
|
|
66
87
|
formData.value = Object.assign({}, props.initialData)
|
|
67
88
|
}
|
|
89
|
+
isSavedAndStay.value = false
|
|
68
90
|
}
|
|
69
91
|
|
|
92
|
+
const operation = ref({ isDataChange, isCreating, isSaving, save, cancel })
|
|
93
|
+
|
|
70
94
|
watchEffect(loadFormData)
|
|
71
95
|
|
|
72
96
|
watch(() => isShowing.value, (newValue) => {
|
|
@@ -85,7 +109,7 @@ watch(() => isShowing.value, (newValue) => {
|
|
|
85
109
|
<VCard>
|
|
86
110
|
<VToolbar>
|
|
87
111
|
<VToolbarTitle>
|
|
88
|
-
<slot name="title">
|
|
112
|
+
<slot name="title" :operation="operation">
|
|
89
113
|
{{ (isCreating) ? "New" : "Edit" }} {{ title }}
|
|
90
114
|
</slot>
|
|
91
115
|
</VToolbarTitle>
|
|
@@ -113,24 +137,26 @@ watch(() => isShowing.value, (newValue) => {
|
|
|
113
137
|
</form-pad>
|
|
114
138
|
</VCardText>
|
|
115
139
|
<VCardActions>
|
|
116
|
-
<
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
<slot name="action" :operation="operation">
|
|
141
|
+
<VSpacer />
|
|
142
|
+
<VBtn
|
|
143
|
+
color="primary"
|
|
144
|
+
variant="flat"
|
|
145
|
+
:loading="isSaving"
|
|
146
|
+
:disabled="!isDataChange"
|
|
147
|
+
@click="save"
|
|
148
|
+
>
|
|
149
|
+
{{ saveCaption }}
|
|
150
|
+
</VBtn>
|
|
151
|
+
<VBtn
|
|
152
|
+
color="error"
|
|
153
|
+
variant="flat"
|
|
154
|
+
:disabled="isSaving"
|
|
155
|
+
@click="cancel"
|
|
156
|
+
>
|
|
157
|
+
{{ (!isDataChange) ? closeCaption : cancelCaption }}
|
|
158
|
+
</VBtn>
|
|
159
|
+
</slot>
|
|
134
160
|
</VCardActions>
|
|
135
161
|
</VCard>
|
|
136
162
|
</v-dialog>
|
|
@@ -23,6 +23,8 @@ interface Props extends /* @vue-ignore */ InstanceType<typeof VDataTable['$props
|
|
|
23
23
|
searchable?: boolean
|
|
24
24
|
inputPad?: boolean
|
|
25
25
|
inputPadOnly?: boolean
|
|
26
|
+
saveAndStay?: boolean
|
|
27
|
+
stringFields?: Array<string>
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
const props = withDefaults(defineProps<Props>(), {
|
|
@@ -36,6 +38,8 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
36
38
|
searchable: true,
|
|
37
39
|
inputPad: false,
|
|
38
40
|
inputPadOnly: false,
|
|
41
|
+
saveAndStay: false,
|
|
42
|
+
stringFields: ()=>[],
|
|
39
43
|
})
|
|
40
44
|
|
|
41
45
|
const emit = defineEmits(['update:modelValue'])
|
|
@@ -85,6 +89,7 @@ function createItem(item: Record<string, any>, callback?: FormDialogCallback) {
|
|
|
85
89
|
|
|
86
90
|
items.value.push(item)
|
|
87
91
|
|
|
92
|
+
if (callback && callback.setData) callback.setData(item)
|
|
88
93
|
if (callback) callback.done()
|
|
89
94
|
}
|
|
90
95
|
|
|
@@ -102,6 +107,7 @@ function updateItem(newItem: Record<string, any>, callback?: FormDialogCallback)
|
|
|
102
107
|
items.value[index] = newItem
|
|
103
108
|
}
|
|
104
109
|
|
|
110
|
+
if (callback && callback.setData) callback.setData(newItem)
|
|
105
111
|
if (callback) callback.done()
|
|
106
112
|
}
|
|
107
113
|
|
|
@@ -238,6 +244,7 @@ defineExpose({
|
|
|
238
244
|
variant="flat"
|
|
239
245
|
@import="importItems"
|
|
240
246
|
:color="toolbarColor"
|
|
247
|
+
:stringFields="props.stringFields"
|
|
241
248
|
/>
|
|
242
249
|
<ExportCSV
|
|
243
250
|
v-if="props.exportable && items.length && !(isReadonly.value || isDisabled.value)"
|
|
@@ -246,6 +253,7 @@ defineExpose({
|
|
|
246
253
|
:file-name="title"
|
|
247
254
|
:model-value="items"
|
|
248
255
|
:color="toolbarColor"
|
|
256
|
+
:stringFields="props.stringFields"
|
|
249
257
|
/>
|
|
250
258
|
<VBtn
|
|
251
259
|
v-if="props.insertable && !props.inputPadOnly && !(isReadonly.value || isDisabled.value)"
|
|
@@ -313,6 +321,7 @@ defineExpose({
|
|
|
313
321
|
:form-data="currentItem"
|
|
314
322
|
@create="createItem"
|
|
315
323
|
@update="updateItem"
|
|
324
|
+
:saveAndStay="saveAndStay"
|
|
316
325
|
v-if="!props.inputPadOnly"
|
|
317
326
|
>
|
|
318
327
|
<template #default="slotData">
|
|
@@ -321,6 +330,18 @@ defineExpose({
|
|
|
321
330
|
v-bind="slotData"
|
|
322
331
|
/>
|
|
323
332
|
</template>
|
|
333
|
+
<template #title="slotData">
|
|
334
|
+
<slot
|
|
335
|
+
name="formTitle"
|
|
336
|
+
v-bind="slotData"
|
|
337
|
+
/>
|
|
338
|
+
</template>
|
|
339
|
+
<template #action="slotData">
|
|
340
|
+
<slot
|
|
341
|
+
name="formAction"
|
|
342
|
+
v-bind="slotData"
|
|
343
|
+
/>
|
|
344
|
+
</template>
|
|
324
345
|
</FormDialog>
|
|
325
346
|
</v-card>
|
|
326
347
|
<slot name="inputPad" :operation="operation" :isReadonly="isReadonly" :isDisabled="isDisabled">
|
|
@@ -15,6 +15,8 @@ interface Props extends /* @vue-ignore */ InstanceType<typeof VAutocomplete['$pr
|
|
|
15
15
|
filterText?: string
|
|
16
16
|
waitForFilter?: boolean
|
|
17
17
|
waitForFilterText?: string
|
|
18
|
+
|
|
19
|
+
cache?: boolean | number
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
const props = withDefaults(defineProps<Props>(), {
|
|
@@ -24,6 +26,8 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
24
26
|
lang: 'TH',
|
|
25
27
|
noDataText: 'ไม่พบข้อมูล',
|
|
26
28
|
waitForFilter: false,
|
|
29
|
+
|
|
30
|
+
cache: false,
|
|
27
31
|
})
|
|
28
32
|
|
|
29
33
|
const computedModelName = computed(()=>{
|
|
@@ -78,6 +82,7 @@ const computedSortBy = computed(()=>{
|
|
|
78
82
|
item-value="itemCode"
|
|
79
83
|
:no-data-text="computedNoDataText"
|
|
80
84
|
:show-code="props.showCode"
|
|
85
|
+
:cache="props.cache"
|
|
81
86
|
>
|
|
82
87
|
<template
|
|
83
88
|
v-for="(_, name, index) in ($slots as {})"
|
|
@@ -5,12 +5,15 @@ interface Props {
|
|
|
5
5
|
groupKey?: string | null
|
|
6
6
|
itemCode?: string | null
|
|
7
7
|
locale?: string
|
|
8
|
+
cache?: boolean | number
|
|
9
|
+
|
|
8
10
|
notFoundText?: string
|
|
9
11
|
placeholder?: string
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
const props = withDefaults(defineProps<Props>(), {
|
|
13
15
|
locale: 'TH',
|
|
16
|
+
cache: false,
|
|
14
17
|
})
|
|
15
18
|
|
|
16
19
|
const computedNotFoundText = computed(()=>{
|
|
@@ -35,5 +38,6 @@ const computedItemTitle = computed(()=>{
|
|
|
35
38
|
:item-title="computedItemTitle"
|
|
36
39
|
:not-found-text="computedNotFoundText"
|
|
37
40
|
:placeholder="computedPlaceholder"
|
|
41
|
+
:cache="props.cache"
|
|
38
42
|
></model-label>
|
|
39
43
|
</template>
|
|
@@ -16,7 +16,7 @@ interface Props extends /* @vue-ignore */ InstanceType<typeof VAutocomplete['$pr
|
|
|
16
16
|
itemTitle: string
|
|
17
17
|
itemValue: string
|
|
18
18
|
fields?: Array<string | object>
|
|
19
|
-
cache?: boolean
|
|
19
|
+
cache?: boolean | number
|
|
20
20
|
|
|
21
21
|
serverSearch?: boolean
|
|
22
22
|
serverSearchKey?: string
|
|
@@ -20,6 +20,8 @@ interface Props extends /* @vue-ignore */ InstanceType<typeof VDataTable['$props
|
|
|
20
20
|
insertable?: boolean
|
|
21
21
|
searchable?: boolean
|
|
22
22
|
search?: string
|
|
23
|
+
saveAndStay?: boolean
|
|
24
|
+
stringFields?: Array<string>
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
const props = withDefaults(defineProps<Props & GraphqlModelProps>(), {
|
|
@@ -30,9 +32,11 @@ const props = withDefaults(defineProps<Props & GraphqlModelProps>(), {
|
|
|
30
32
|
exportable: true,
|
|
31
33
|
insertable: true,
|
|
32
34
|
searchable: true,
|
|
35
|
+
saveAndStay: false,
|
|
33
36
|
modelKey: 'id',
|
|
34
37
|
modelBy: undefined,
|
|
35
38
|
fields: () => [],
|
|
39
|
+
stringFields: ()=>[],
|
|
36
40
|
})
|
|
37
41
|
|
|
38
42
|
const attrs = useAttrs()
|
|
@@ -124,6 +128,7 @@ defineExpose({ reload,operation })
|
|
|
124
128
|
icon="mdi mdi-file-upload"
|
|
125
129
|
variant="flat"
|
|
126
130
|
:color="toolbarColor"
|
|
131
|
+
:stringFields="props.stringFields"
|
|
127
132
|
@import="importItems"
|
|
128
133
|
/>
|
|
129
134
|
<ExportCSV
|
|
@@ -133,6 +138,7 @@ defineExpose({ reload,operation })
|
|
|
133
138
|
:file-name="title"
|
|
134
139
|
:model-value="items"
|
|
135
140
|
:color="toolbarColor"
|
|
141
|
+
:stringFields="props.stringFields"
|
|
136
142
|
/>
|
|
137
143
|
<VBtn
|
|
138
144
|
v-if="canCreate && props.insertable"
|
|
@@ -238,6 +244,7 @@ defineExpose({ reload,operation })
|
|
|
238
244
|
:form-data="currentItem"
|
|
239
245
|
@create="createItem"
|
|
240
246
|
@update="updateItem"
|
|
247
|
+
:saveAndStay="saveAndStay"
|
|
241
248
|
>
|
|
242
249
|
<template #default="slotData">
|
|
243
250
|
<slot
|
|
@@ -245,6 +252,18 @@ defineExpose({ reload,operation })
|
|
|
245
252
|
v-bind="slotData"
|
|
246
253
|
/>
|
|
247
254
|
</template>
|
|
255
|
+
<template #title="slotData">
|
|
256
|
+
<slot
|
|
257
|
+
name="formTitle"
|
|
258
|
+
v-bind="slotData"
|
|
259
|
+
/>
|
|
260
|
+
</template>
|
|
261
|
+
<template #action="slotData">
|
|
262
|
+
<slot
|
|
263
|
+
name="formAction"
|
|
264
|
+
v-bind="slotData"
|
|
265
|
+
/>
|
|
266
|
+
</template>
|
|
248
267
|
</FormDialog>
|
|
249
268
|
</v-card>
|
|
250
269
|
</template>
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { computedAsync } from '@vueuse/core'
|
|
3
3
|
import { useGraphQlOperation } from '../../composables/graphqlOperation'
|
|
4
|
-
import {concat} from "lodash-es";
|
|
4
|
+
import { concat } from "lodash-es";
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
modelName: string
|
|
8
8
|
modelBy?: object
|
|
9
9
|
itemTitle: string | ((result:Record<string,any>)=>void)
|
|
10
10
|
fields?: Array<string | object>
|
|
11
|
-
cache?: boolean
|
|
11
|
+
cache?: boolean | number
|
|
12
12
|
|
|
13
13
|
notFoundText?: string
|
|
14
14
|
placeholder?: string
|
|
@@ -40,5 +40,5 @@ const modelItemValue = computedAsync<string>(async () => {
|
|
|
40
40
|
</script>
|
|
41
41
|
|
|
42
42
|
<template>
|
|
43
|
-
{{ modelItemValue }}
|
|
43
|
+
<span>{{ modelItemValue }}</span>
|
|
44
44
|
</template>
|
|
@@ -2,8 +2,9 @@ import type { UseFetchOptions } from 'nuxt/app';
|
|
|
2
2
|
import type { SearchParameters } from 'ofetch';
|
|
3
3
|
export declare function useApi(): {
|
|
4
4
|
urlBuilder: (url: string | string[]) => string;
|
|
5
|
-
get: (url: string | string[], body?: Record<string, any> | [], params?: SearchParameters, options?: UseFetchOptions<unknown
|
|
6
|
-
getPromise: (url: string | string[], body?: Record<string, any> | [], params?: SearchParameters, options?: UseFetchOptions<unknown
|
|
7
|
-
post: (url: string | string[], body?: Record<string, any> | [], params?: SearchParameters, options?: UseFetchOptions<unknown
|
|
8
|
-
postPromise: (url: string | string[], body?: Record<string, any> | [], params?: SearchParameters, options?: UseFetchOptions<unknown
|
|
5
|
+
get: (url: string | string[], body?: Record<string, any> | [], params?: SearchParameters, options?: UseFetchOptions<unknown>, cache?: boolean | number) => Promise<unknown>;
|
|
6
|
+
getPromise: (url: string | string[], body?: Record<string, any> | [], params?: SearchParameters, options?: UseFetchOptions<unknown>, cache?: boolean | number) => Promise<unknown>;
|
|
7
|
+
post: (url: string | string[], body?: Record<string, any> | [], params?: SearchParameters, options?: UseFetchOptions<unknown>, cache?: boolean | number) => Promise<unknown>;
|
|
8
|
+
postPromise: (url: string | string[], body?: Record<string, any> | [], params?: SearchParameters, options?: UseFetchOptions<unknown>, cache?: boolean | number) => Promise<unknown>;
|
|
9
|
+
hashKey: (data: any) => Promise<string>;
|
|
9
10
|
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ofetch } from "ofetch";
|
|
2
2
|
import { trimEnd, trimStart } from "lodash-es";
|
|
3
|
+
import ls from "localstorage-ttl";
|
|
4
|
+
import { stableStringify } from "../utils/object.js";
|
|
5
|
+
import { sha256 } from "../utils/hash.js";
|
|
3
6
|
import { useAuthentication, useRuntimeConfig } from "#imports";
|
|
4
7
|
export function useApi() {
|
|
5
8
|
const config = useRuntimeConfig();
|
|
@@ -39,17 +42,43 @@ export function useApi() {
|
|
|
39
42
|
headers: finalHeaders
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
|
-
function get(url, body, params, options) {
|
|
43
|
-
return
|
|
45
|
+
function get(url, body, params, options, cache = false) {
|
|
46
|
+
return getPromise(url, body, params, options, cache);
|
|
44
47
|
}
|
|
45
|
-
function getPromise(url, body, params, options) {
|
|
46
|
-
return
|
|
48
|
+
function getPromise(url, body, params, options, cache = false) {
|
|
49
|
+
return ofetchWithCache(url, "GET", body, params, options, cache);
|
|
47
50
|
}
|
|
48
|
-
function post(url, body, params, options) {
|
|
49
|
-
return
|
|
51
|
+
function post(url, body, params, options, cache = false) {
|
|
52
|
+
return postPromise(url, body, params, options, cache);
|
|
50
53
|
}
|
|
51
|
-
function postPromise(url, body, params, options) {
|
|
52
|
-
return
|
|
54
|
+
function postPromise(url, body, params, options, cache = false) {
|
|
55
|
+
return ofetchWithCache(url, "POST", body, params, options, cache);
|
|
53
56
|
}
|
|
54
|
-
|
|
57
|
+
async function hashKey(data) {
|
|
58
|
+
const jsonString = stableStringify(data);
|
|
59
|
+
return sha256(jsonString);
|
|
60
|
+
}
|
|
61
|
+
async function ofetchWithCache(url, method, body, params, options, cache) {
|
|
62
|
+
const keyData = { url: urlBuilder(url), method, body, params, options };
|
|
63
|
+
let ttl = 0;
|
|
64
|
+
if (cache) {
|
|
65
|
+
if (typeof cache === "boolean") ttl = 5 * 60 * 1e3;
|
|
66
|
+
else {
|
|
67
|
+
ttl = +cache * 60 * 1e3;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (ttl === 0) {
|
|
71
|
+
return ofetch(urlBuilder(url), optionBuilder(method, body, params, options));
|
|
72
|
+
}
|
|
73
|
+
const key = "api-cache-" + await hashKey(keyData);
|
|
74
|
+
const cached = ls.get(key);
|
|
75
|
+
if (cached) {
|
|
76
|
+
return Promise.resolve(cached);
|
|
77
|
+
}
|
|
78
|
+
return ofetch(urlBuilder(url), optionBuilder(method, body, params, options)).then((result) => {
|
|
79
|
+
ls.set(key, result, ttl);
|
|
80
|
+
return result;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return { urlBuilder, get, getPromise, post, postPromise, hashKey };
|
|
55
84
|
}
|
|
@@ -11,7 +11,7 @@ declare type VariableOptions = {
|
|
|
11
11
|
};
|
|
12
12
|
export declare function useGraphQl(): {
|
|
13
13
|
query: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions, cache?: boolean) => import("#app").AsyncData<(T extends any[] ? T : T extends Record<string, any> ? keyof T extends (T extends T ? keyof T extends string ? string & keyof T : never : never) ? T : (T extends T ? keyof T extends string ? string & keyof T : never : never) extends never ? T : Pick<T, T extends T ? keyof T extends string ? string & keyof T : never : never> : T) | null, import("#app").NuxtError<unknown> | null>;
|
|
14
|
-
queryPromise: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions, cache?: boolean) => Promise<T>;
|
|
14
|
+
queryPromise: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions, cache?: boolean | number) => Promise<T>;
|
|
15
15
|
mutation: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions) => UseMutationReturn<any, any>;
|
|
16
16
|
mutationPromise: <T>(operation: string, fields: Array<string | Object> | ClassConstructor<any>, variables?: VariableOptions) => Promise<T>;
|
|
17
17
|
};
|
|
@@ -3,12 +3,12 @@ import { classAttributes, isClassConstructor } from "../utils/object.js";
|
|
|
3
3
|
import { gql, useAsyncQuery, useMutation, useRuntimeConfig } from "#imports";
|
|
4
4
|
import { useApi } from "./api.js";
|
|
5
5
|
export function useGraphQl() {
|
|
6
|
-
function simplePromiseCall(operation, query2, variables) {
|
|
6
|
+
function simplePromiseCall(operation, query2, variables, cache = false) {
|
|
7
7
|
return new Promise((resolve, reject) => {
|
|
8
8
|
useApi().postPromise(useRuntimeConfig().public.WS_GRAPHQL, {
|
|
9
9
|
query: query2,
|
|
10
10
|
variables
|
|
11
|
-
}).then((result) => {
|
|
11
|
+
}, void 0, void 0, cache).then((result) => {
|
|
12
12
|
if (result.errors) reject(result.errors.map((error) => {
|
|
13
13
|
return error.message;
|
|
14
14
|
}).join("\n"));
|
|
@@ -38,7 +38,7 @@ export function useGraphQl() {
|
|
|
38
38
|
function queryPromise(operation, fields, variables, cache = false) {
|
|
39
39
|
if (isClassConstructor(fields)) fields = classAttributes(fields);
|
|
40
40
|
const builder = gqlQuery({ operation, fields, variables });
|
|
41
|
-
return simplePromiseCall(operation, builder.query, builder.variables);
|
|
41
|
+
return simplePromiseCall(operation, builder.query, builder.variables, cache);
|
|
42
42
|
}
|
|
43
43
|
function mutation(operation, fields, variables) {
|
|
44
44
|
if (isClassConstructor(fields)) fields = classAttributes(fields);
|
|
@@ -13,12 +13,12 @@ export declare function useGraphqlModel<T extends GraphqlModelProps>(props: T):
|
|
|
13
13
|
search: import("vue").Ref<string | undefined, string | undefined>;
|
|
14
14
|
setSearch: (keyword: string) => void;
|
|
15
15
|
currentOptions: import("vue").Ref<any, any>;
|
|
16
|
-
operationCreate: import("vue").ComputedRef<import("
|
|
17
|
-
operationUpdate: import("vue").ComputedRef<import("
|
|
18
|
-
operationDelete: import("vue").ComputedRef<import("
|
|
19
|
-
operationRead: import("vue").ComputedRef<import("
|
|
20
|
-
operationReadPageable: import("vue").ComputedRef<import("
|
|
21
|
-
operationSearch: import("vue").ComputedRef<import("
|
|
16
|
+
operationCreate: import("vue").ComputedRef<import("../types/graphqlOperation").graphqlOperationObject<any, any>>;
|
|
17
|
+
operationUpdate: import("vue").ComputedRef<import("../types/graphqlOperation").graphqlOperationObject<any, any>>;
|
|
18
|
+
operationDelete: import("vue").ComputedRef<import("../types/graphqlOperation").graphqlOperationObject<any, any>>;
|
|
19
|
+
operationRead: import("vue").ComputedRef<import("../types/graphqlOperation").graphqlOperationObject<any, any>>;
|
|
20
|
+
operationReadPageable: import("vue").ComputedRef<import("../types/graphqlOperation").graphqlOperationObject<any, any>>;
|
|
21
|
+
operationSearch: import("vue").ComputedRef<import("../types/graphqlOperation").graphqlOperationObject<any, any>>;
|
|
22
22
|
fields: import("vue").ComputedRef<(string | object)[]>;
|
|
23
23
|
canServerPageable: import("vue").ComputedRef<boolean>;
|
|
24
24
|
canServerSearch: import("vue").ComputedRef<boolean>;
|
|
@@ -61,6 +61,7 @@ export function useGraphqlModel(props) {
|
|
|
61
61
|
if (canServerPageable.value) {
|
|
62
62
|
if (!importing) loadItems(currentOptions.value);
|
|
63
63
|
} else items.value.push(result);
|
|
64
|
+
if (callback && callback.setData) callback.setData(result);
|
|
64
65
|
}).catch((error) => {
|
|
65
66
|
alert?.addAlert({ alertType: "error", message: error });
|
|
66
67
|
}).finally(() => {
|
|
@@ -98,6 +99,7 @@ export function useGraphqlModel(props) {
|
|
|
98
99
|
items.value[index] = result;
|
|
99
100
|
}
|
|
100
101
|
}
|
|
102
|
+
if (callback && callback.setData) callback.setData(result);
|
|
101
103
|
}).catch((error) => {
|
|
102
104
|
alert?.addAlert({ alertType: "error", message: error });
|
|
103
105
|
}).finally(() => {
|
|
@@ -4,10 +4,10 @@ export type GraphqlModelItemProps = Omit<GraphqlModelConfigProps, 'operationSear
|
|
|
4
4
|
export declare function useGraphqlModelItem<T extends GraphqlModelItemProps>(props: T): {
|
|
5
5
|
modelBy: import("vue").Ref<object | undefined, object | undefined>;
|
|
6
6
|
item: import("vue").Ref<Record<string, any> | undefined, Record<string, any> | undefined>;
|
|
7
|
-
operationCreate: import("vue").ComputedRef<import("
|
|
8
|
-
operationUpdate: import("vue").ComputedRef<import("
|
|
9
|
-
operationDelete: import("vue").ComputedRef<import("
|
|
10
|
-
operationRead: import("vue").ComputedRef<import("
|
|
7
|
+
operationCreate: import("vue").ComputedRef<import("../types/graphqlOperation").graphqlOperationObject<any, any>>;
|
|
8
|
+
operationUpdate: import("vue").ComputedRef<import("../types/graphqlOperation").graphqlOperationObject<any, any>>;
|
|
9
|
+
operationDelete: import("vue").ComputedRef<import("../types/graphqlOperation").graphqlOperationObject<any, any>>;
|
|
10
|
+
operationRead: import("vue").ComputedRef<import("../types/graphqlOperation").graphqlOperationObject<any, any>>;
|
|
11
11
|
fields: import("vue").ComputedRef<(string | object)[]>;
|
|
12
12
|
canCreate: import("vue").ComputedRef<boolean>;
|
|
13
13
|
canUpdate: import("vue").ComputedRef<boolean>;
|
|
@@ -12,10 +12,10 @@ export interface GraphqlModelConfigProps {
|
|
|
12
12
|
fields?: Array<string | object>;
|
|
13
13
|
}
|
|
14
14
|
export declare function useGraphqlModelOperation<T extends GraphqlModelConfigProps>(props: T): {
|
|
15
|
-
operationCreate: import("vue").ComputedRef<
|
|
16
|
-
operationUpdate: import("vue").ComputedRef<
|
|
17
|
-
operationDelete: import("vue").ComputedRef<
|
|
18
|
-
operationRead: import("vue").ComputedRef<
|
|
19
|
-
operationReadPageable: import("vue").ComputedRef<
|
|
20
|
-
operationSearch: import("vue").ComputedRef<
|
|
15
|
+
operationCreate: import("vue").ComputedRef<graphqlOperationObject<any, any>>;
|
|
16
|
+
operationUpdate: import("vue").ComputedRef<graphqlOperationObject<any, any>>;
|
|
17
|
+
operationDelete: import("vue").ComputedRef<graphqlOperationObject<any, any>>;
|
|
18
|
+
operationRead: import("vue").ComputedRef<graphqlOperationObject<any, any>>;
|
|
19
|
+
operationReadPageable: import("vue").ComputedRef<graphqlOperationObject<any, any>>;
|
|
20
|
+
operationSearch: import("vue").ComputedRef<graphqlOperationObject<any, any>>;
|
|
21
21
|
};
|
|
@@ -7,4 +7,4 @@ export declare function buildVariables(outputVariables?: graphqlVariable[], inpu
|
|
|
7
7
|
export declare function buildRequiredInputFields(variables: graphqlVariable[] | undefined, inputField?: string): string[];
|
|
8
8
|
export declare function useGraphQlOperation<T>(operationType: string, operation: string, fields?: Array<string | Object> | ClassConstructor<any>, variables?: {
|
|
9
9
|
[p: string]: any;
|
|
10
|
-
}, cache?: boolean): Promise<T>;
|
|
10
|
+
}, cache?: boolean | number): Promise<T>;
|
|
@@ -10,7 +10,7 @@ export interface graphqlOperationObject<T, U> {
|
|
|
10
10
|
fields?: graphqlTypeObject
|
|
11
11
|
operationType: 'Query' | 'Mutation'
|
|
12
12
|
name: string
|
|
13
|
-
call: (fields?: Array<string | Object>, variables?: U) => Promise<T>
|
|
13
|
+
call: (fields?: Array<string | Object>, variables?: U, cache?: boolean | number) => Promise<T>
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export interface graphqlTypeObject {
|
|
@@ -6,11 +6,11 @@ export declare const Datetime: () => {
|
|
|
6
6
|
luxonDateTime: DateTimeMaybeValid;
|
|
7
7
|
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => {
|
|
8
8
|
luxonDateTime: DateTimeMaybeValid;
|
|
9
|
-
fromString: any;
|
|
10
|
-
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
|
|
11
|
-
fromISO: (dateTime: string, locale?: supportedLocale) => any;
|
|
12
|
-
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
|
|
13
|
-
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
|
|
9
|
+
fromString: /*elided*/ any;
|
|
10
|
+
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => /*elided*/ any;
|
|
11
|
+
fromISO: (dateTime: string, locale?: supportedLocale) => /*elided*/ any;
|
|
12
|
+
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => /*elided*/ any;
|
|
13
|
+
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => /*elided*/ any;
|
|
14
14
|
toFormat: (format: string, locale?: supportedLocale) => string;
|
|
15
15
|
toISO: () => string | null;
|
|
16
16
|
toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => string;
|
|
@@ -28,15 +28,15 @@ export declare const Datetime: () => {
|
|
|
28
28
|
isFutureDate: () => boolean;
|
|
29
29
|
isHappen: () => boolean;
|
|
30
30
|
isHappenDate: () => boolean;
|
|
31
|
-
now: () => any;
|
|
31
|
+
now: () => /*elided*/ any;
|
|
32
32
|
};
|
|
33
33
|
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => {
|
|
34
34
|
luxonDateTime: DateTimeMaybeValid;
|
|
35
|
-
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
|
|
36
|
-
fromStringTime: any;
|
|
37
|
-
fromISO: (dateTime: string, locale?: supportedLocale) => any;
|
|
38
|
-
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
|
|
39
|
-
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
|
|
35
|
+
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => /*elided*/ any;
|
|
36
|
+
fromStringTime: /*elided*/ any;
|
|
37
|
+
fromISO: (dateTime: string, locale?: supportedLocale) => /*elided*/ any;
|
|
38
|
+
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => /*elided*/ any;
|
|
39
|
+
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => /*elided*/ any;
|
|
40
40
|
toFormat: (format: string, locale?: supportedLocale) => string;
|
|
41
41
|
toISO: () => string | null;
|
|
42
42
|
toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => string;
|
|
@@ -54,15 +54,15 @@ export declare const Datetime: () => {
|
|
|
54
54
|
isFutureDate: () => boolean;
|
|
55
55
|
isHappen: () => boolean;
|
|
56
56
|
isHappenDate: () => boolean;
|
|
57
|
-
now: () => any;
|
|
57
|
+
now: () => /*elided*/ any;
|
|
58
58
|
};
|
|
59
59
|
fromISO: (dateTime: string, locale?: supportedLocale) => {
|
|
60
60
|
luxonDateTime: DateTimeMaybeValid;
|
|
61
|
-
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
|
|
62
|
-
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
|
|
63
|
-
fromISO: any;
|
|
64
|
-
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
|
|
65
|
-
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
|
|
61
|
+
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => /*elided*/ any;
|
|
62
|
+
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => /*elided*/ any;
|
|
63
|
+
fromISO: /*elided*/ any;
|
|
64
|
+
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => /*elided*/ any;
|
|
65
|
+
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => /*elided*/ any;
|
|
66
66
|
toFormat: (format: string, locale?: supportedLocale) => string;
|
|
67
67
|
toISO: () => string | null;
|
|
68
68
|
toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => string;
|
|
@@ -80,15 +80,15 @@ export declare const Datetime: () => {
|
|
|
80
80
|
isFutureDate: () => boolean;
|
|
81
81
|
isHappen: () => boolean;
|
|
82
82
|
isHappenDate: () => boolean;
|
|
83
|
-
now: () => any;
|
|
83
|
+
now: () => /*elided*/ any;
|
|
84
84
|
};
|
|
85
85
|
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => {
|
|
86
86
|
luxonDateTime: DateTimeMaybeValid;
|
|
87
|
-
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
|
|
88
|
-
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
|
|
89
|
-
fromISO: (dateTime: string, locale?: supportedLocale) => any;
|
|
90
|
-
fromObject: any;
|
|
91
|
-
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
|
|
87
|
+
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => /*elided*/ any;
|
|
88
|
+
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => /*elided*/ any;
|
|
89
|
+
fromISO: (dateTime: string, locale?: supportedLocale) => /*elided*/ any;
|
|
90
|
+
fromObject: /*elided*/ any;
|
|
91
|
+
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => /*elided*/ any;
|
|
92
92
|
toFormat: (format: string, locale?: supportedLocale) => string;
|
|
93
93
|
toISO: () => string | null;
|
|
94
94
|
toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => string;
|
|
@@ -106,15 +106,15 @@ export declare const Datetime: () => {
|
|
|
106
106
|
isFutureDate: () => boolean;
|
|
107
107
|
isHappen: () => boolean;
|
|
108
108
|
isHappenDate: () => boolean;
|
|
109
|
-
now: () => any;
|
|
109
|
+
now: () => /*elided*/ any;
|
|
110
110
|
};
|
|
111
111
|
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => {
|
|
112
112
|
luxonDateTime: DateTimeMaybeValid;
|
|
113
|
-
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
|
|
114
|
-
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
|
|
115
|
-
fromISO: (dateTime: string, locale?: supportedLocale) => any;
|
|
116
|
-
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
|
|
117
|
-
setDateTime: any;
|
|
113
|
+
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => /*elided*/ any;
|
|
114
|
+
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => /*elided*/ any;
|
|
115
|
+
fromISO: (dateTime: string, locale?: supportedLocale) => /*elided*/ any;
|
|
116
|
+
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => /*elided*/ any;
|
|
117
|
+
setDateTime: /*elided*/ any;
|
|
118
118
|
toFormat: (format: string, locale?: supportedLocale) => string;
|
|
119
119
|
toISO: () => string | null;
|
|
120
120
|
toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => string;
|
|
@@ -132,7 +132,7 @@ export declare const Datetime: () => {
|
|
|
132
132
|
isFutureDate: () => boolean;
|
|
133
133
|
isHappen: () => boolean;
|
|
134
134
|
isHappenDate: () => boolean;
|
|
135
|
-
now: () => any;
|
|
135
|
+
now: () => /*elided*/ any;
|
|
136
136
|
};
|
|
137
137
|
toFormat: (format: string, locale?: supportedLocale) => string;
|
|
138
138
|
toISO: () => string | null;
|
|
@@ -153,136 +153,11 @@ export declare const Datetime: () => {
|
|
|
153
153
|
isHappenDate: () => boolean;
|
|
154
154
|
now: () => {
|
|
155
155
|
luxonDateTime: DateTimeMaybeValid;
|
|
156
|
-
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) =>
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
|
|
162
|
-
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
|
|
163
|
-
toFormat: (format: string, locale?: supportedLocale) => string;
|
|
164
|
-
toISO: () => string | null;
|
|
165
|
-
toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => string;
|
|
166
|
-
toTinyDate: (locale?: supportedLocale) => string;
|
|
167
|
-
toMonthShortDate: (locale?: supportedLocale) => string;
|
|
168
|
-
toShortDate: (locale?: supportedLocale) => string;
|
|
169
|
-
toLongDate: (locale?: supportedLocale) => string;
|
|
170
|
-
toTinyDateTime: (locale?: supportedLocale) => string;
|
|
171
|
-
toShortDateTime: (locale?: supportedLocale) => string;
|
|
172
|
-
toLongDateTime: (locale?: supportedLocale) => string;
|
|
173
|
-
isAfter: (compareDate: string) => boolean;
|
|
174
|
-
isBefore: (compareDate: string) => boolean;
|
|
175
|
-
isEqual: (compareDate: string) => boolean;
|
|
176
|
-
isFuture: () => boolean;
|
|
177
|
-
isFutureDate: () => boolean;
|
|
178
|
-
isHappen: () => boolean;
|
|
179
|
-
isHappenDate: () => boolean;
|
|
180
|
-
now: () => any;
|
|
181
|
-
};
|
|
182
|
-
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => {
|
|
183
|
-
luxonDateTime: DateTimeMaybeValid;
|
|
184
|
-
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
|
|
185
|
-
fromStringTime: any;
|
|
186
|
-
fromISO: (dateTime: string, locale?: supportedLocale) => any;
|
|
187
|
-
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
|
|
188
|
-
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
|
|
189
|
-
toFormat: (format: string, locale?: supportedLocale) => string;
|
|
190
|
-
toISO: () => string | null;
|
|
191
|
-
toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => string;
|
|
192
|
-
toTinyDate: (locale?: supportedLocale) => string;
|
|
193
|
-
toMonthShortDate: (locale?: supportedLocale) => string;
|
|
194
|
-
toShortDate: (locale?: supportedLocale) => string;
|
|
195
|
-
toLongDate: (locale?: supportedLocale) => string;
|
|
196
|
-
toTinyDateTime: (locale?: supportedLocale) => string;
|
|
197
|
-
toShortDateTime: (locale?: supportedLocale) => string;
|
|
198
|
-
toLongDateTime: (locale?: supportedLocale) => string;
|
|
199
|
-
isAfter: (compareDate: string) => boolean;
|
|
200
|
-
isBefore: (compareDate: string) => boolean;
|
|
201
|
-
isEqual: (compareDate: string) => boolean;
|
|
202
|
-
isFuture: () => boolean;
|
|
203
|
-
isFutureDate: () => boolean;
|
|
204
|
-
isHappen: () => boolean;
|
|
205
|
-
isHappenDate: () => boolean;
|
|
206
|
-
now: () => any;
|
|
207
|
-
};
|
|
208
|
-
fromISO: (dateTime: string, locale?: supportedLocale) => {
|
|
209
|
-
luxonDateTime: DateTimeMaybeValid;
|
|
210
|
-
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
|
|
211
|
-
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
|
|
212
|
-
fromISO: any;
|
|
213
|
-
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
|
|
214
|
-
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
|
|
215
|
-
toFormat: (format: string, locale?: supportedLocale) => string;
|
|
216
|
-
toISO: () => string | null;
|
|
217
|
-
toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => string;
|
|
218
|
-
toTinyDate: (locale?: supportedLocale) => string;
|
|
219
|
-
toMonthShortDate: (locale?: supportedLocale) => string;
|
|
220
|
-
toShortDate: (locale?: supportedLocale) => string;
|
|
221
|
-
toLongDate: (locale?: supportedLocale) => string;
|
|
222
|
-
toTinyDateTime: (locale?: supportedLocale) => string;
|
|
223
|
-
toShortDateTime: (locale?: supportedLocale) => string;
|
|
224
|
-
toLongDateTime: (locale?: supportedLocale) => string;
|
|
225
|
-
isAfter: (compareDate: string) => boolean;
|
|
226
|
-
isBefore: (compareDate: string) => boolean;
|
|
227
|
-
isEqual: (compareDate: string) => boolean;
|
|
228
|
-
isFuture: () => boolean;
|
|
229
|
-
isFutureDate: () => boolean;
|
|
230
|
-
isHappen: () => boolean;
|
|
231
|
-
isHappenDate: () => boolean;
|
|
232
|
-
now: () => any;
|
|
233
|
-
};
|
|
234
|
-
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => {
|
|
235
|
-
luxonDateTime: DateTimeMaybeValid;
|
|
236
|
-
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
|
|
237
|
-
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
|
|
238
|
-
fromISO: (dateTime: string, locale?: supportedLocale) => any;
|
|
239
|
-
fromObject: any;
|
|
240
|
-
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => any;
|
|
241
|
-
toFormat: (format: string, locale?: supportedLocale) => string;
|
|
242
|
-
toISO: () => string | null;
|
|
243
|
-
toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => string;
|
|
244
|
-
toTinyDate: (locale?: supportedLocale) => string;
|
|
245
|
-
toMonthShortDate: (locale?: supportedLocale) => string;
|
|
246
|
-
toShortDate: (locale?: supportedLocale) => string;
|
|
247
|
-
toLongDate: (locale?: supportedLocale) => string;
|
|
248
|
-
toTinyDateTime: (locale?: supportedLocale) => string;
|
|
249
|
-
toShortDateTime: (locale?: supportedLocale) => string;
|
|
250
|
-
toLongDateTime: (locale?: supportedLocale) => string;
|
|
251
|
-
isAfter: (compareDate: string) => boolean;
|
|
252
|
-
isBefore: (compareDate: string) => boolean;
|
|
253
|
-
isEqual: (compareDate: string) => boolean;
|
|
254
|
-
isFuture: () => boolean;
|
|
255
|
-
isFutureDate: () => boolean;
|
|
256
|
-
isHappen: () => boolean;
|
|
257
|
-
isHappenDate: () => boolean;
|
|
258
|
-
now: () => any;
|
|
259
|
-
};
|
|
260
|
-
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => {
|
|
261
|
-
luxonDateTime: DateTimeMaybeValid;
|
|
262
|
-
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => any;
|
|
263
|
-
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => any;
|
|
264
|
-
fromISO: (dateTime: string, locale?: supportedLocale) => any;
|
|
265
|
-
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => any;
|
|
266
|
-
setDateTime: any;
|
|
267
|
-
toFormat: (format: string, locale?: supportedLocale) => string;
|
|
268
|
-
toISO: () => string | null;
|
|
269
|
-
toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => string;
|
|
270
|
-
toTinyDate: (locale?: supportedLocale) => string;
|
|
271
|
-
toMonthShortDate: (locale?: supportedLocale) => string;
|
|
272
|
-
toShortDate: (locale?: supportedLocale) => string;
|
|
273
|
-
toLongDate: (locale?: supportedLocale) => string;
|
|
274
|
-
toTinyDateTime: (locale?: supportedLocale) => string;
|
|
275
|
-
toShortDateTime: (locale?: supportedLocale) => string;
|
|
276
|
-
toLongDateTime: (locale?: supportedLocale) => string;
|
|
277
|
-
isAfter: (compareDate: string) => boolean;
|
|
278
|
-
isBefore: (compareDate: string) => boolean;
|
|
279
|
-
isEqual: (compareDate: string) => boolean;
|
|
280
|
-
isFuture: () => boolean;
|
|
281
|
-
isFutureDate: () => boolean;
|
|
282
|
-
isHappen: () => boolean;
|
|
283
|
-
isHappenDate: () => boolean;
|
|
284
|
-
now: () => any;
|
|
285
|
-
};
|
|
156
|
+
fromString: (dateTime: string | null, formatDate?: string, locale?: supportedLocale) => /*elided*/ any;
|
|
157
|
+
fromStringTime: (time: string | null, formatTime?: string, locale?: supportedLocale) => /*elided*/ any;
|
|
158
|
+
fromISO: (dateTime: string, locale?: supportedLocale) => /*elided*/ any;
|
|
159
|
+
fromObject: (dateTime: DateObjectUnits, locale?: supportedLocale) => /*elided*/ any;
|
|
160
|
+
setDateTime: (inputDate: DateTime, locale?: supportedLocale) => /*elided*/ any;
|
|
286
161
|
toFormat: (format: string, locale?: supportedLocale) => string;
|
|
287
162
|
toISO: () => string | null;
|
|
288
163
|
toLocaleFormat: (locale: supportedLocale, format: DateTimeFormatOptions) => string;
|
|
@@ -300,7 +175,7 @@ export declare const Datetime: () => {
|
|
|
300
175
|
isFutureDate: () => boolean;
|
|
301
176
|
isHappen: () => boolean;
|
|
302
177
|
isHappenDate: () => boolean;
|
|
303
|
-
now: any;
|
|
178
|
+
now: /*elided*/ any;
|
|
304
179
|
};
|
|
305
180
|
};
|
|
306
181
|
export declare function verifyDateFormat(date: string): string | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sha256(input: string): Promise<string>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export async function sha256(input) {
|
|
2
|
+
const encoder = new TextEncoder();
|
|
3
|
+
const dataBuffer = encoder.encode(input);
|
|
4
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", dataBuffer);
|
|
5
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
6
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
7
|
+
}
|
|
@@ -6,3 +6,4 @@ export declare function onlyClassAttributes<T extends Record<string, any>>(cls:
|
|
|
6
6
|
export declare function classAttributes<T extends Record<string, any>>(cls: ClassConstructor<T>): string[];
|
|
7
7
|
export declare function onlyAttributes(keys: string[], object: Record<string, any>): Record<string, any>;
|
|
8
8
|
export declare function renameAttributes(object: Record<string, any>, mapper: Record<string, string>): Record<string, any>;
|
|
9
|
+
export declare function stableStringify(obj: any): string;
|
|
@@ -25,3 +25,28 @@ export function renameAttributes(object, mapper) {
|
|
|
25
25
|
});
|
|
26
26
|
return returnObject;
|
|
27
27
|
}
|
|
28
|
+
export function stableStringify(obj) {
|
|
29
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
30
|
+
const inner = (value) => {
|
|
31
|
+
if (value === null) return "null";
|
|
32
|
+
if (typeof value === "number") return isFinite(value) ? String(value) : "null";
|
|
33
|
+
if (typeof value === "boolean") return String(value);
|
|
34
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
35
|
+
if (typeof value === "function" || typeof value === "undefined") return "null";
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
return `[${value.map((v) => inner(v)).join(",")}]`;
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === "object") {
|
|
40
|
+
if (seen.has(value)) throw new TypeError("Converting circular structure to JSON");
|
|
41
|
+
seen.add(value);
|
|
42
|
+
const keys = Object.keys(value).sort();
|
|
43
|
+
const props = keys.map((key) => {
|
|
44
|
+
const val = inner(value[key]);
|
|
45
|
+
return `"${key}":${val}`;
|
|
46
|
+
});
|
|
47
|
+
return `{${props.join(",")}}`;
|
|
48
|
+
}
|
|
49
|
+
return "null";
|
|
50
|
+
};
|
|
51
|
+
return inner(obj);
|
|
52
|
+
}
|
package/dist/types.d.mts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
|
+
|
|
3
|
+
import type { default as Module } from './module.js'
|
|
4
|
+
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
+
|
|
7
|
+
export { default } from './module.js'
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
|
+
|
|
3
|
+
import type { default as Module } from './module'
|
|
4
|
+
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
+
|
|
7
|
+
export { default } from './module'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ramathibodi/nuxt-commons",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
4
4
|
"description": "Ramathibodi Nuxt modules for common components",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,68 +52,70 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@codemirror/lang-html": "^6.4.9",
|
|
55
|
-
"@codemirror/lang-javascript": "^6.2.
|
|
55
|
+
"@codemirror/lang-javascript": "^6.2.3",
|
|
56
56
|
"@codemirror/lang-vue": "^0.1.3",
|
|
57
57
|
"@codemirror/theme-one-dark": "^6.1.2",
|
|
58
|
-
"@fortawesome/fontawesome-free": "^6.
|
|
59
|
-
"@fullcalendar/core": "^6.1.
|
|
60
|
-
"@fullcalendar/daygrid": "^6.1.
|
|
61
|
-
"@fullcalendar/interaction": "^6.1.
|
|
62
|
-
"@fullcalendar/list": "^6.1.
|
|
63
|
-
"@fullcalendar/multimonth": "^6.1.
|
|
64
|
-
"@fullcalendar/timegrid": "^6.1.
|
|
65
|
-
"@fullcalendar/vue3": "^6.1.
|
|
58
|
+
"@fortawesome/fontawesome-free": "^6.7.2",
|
|
59
|
+
"@fullcalendar/core": "^6.1.17",
|
|
60
|
+
"@fullcalendar/daygrid": "^6.1.17",
|
|
61
|
+
"@fullcalendar/interaction": "^6.1.17",
|
|
62
|
+
"@fullcalendar/list": "^6.1.17",
|
|
63
|
+
"@fullcalendar/multimonth": "^6.1.17",
|
|
64
|
+
"@fullcalendar/timegrid": "^6.1.17",
|
|
65
|
+
"@fullcalendar/vue3": "^6.1.17",
|
|
66
66
|
"@graphql-codegen/add": "^5.0.3",
|
|
67
|
-
"@graphql-codegen/cli": "^5.0.
|
|
68
|
-
"@graphql-codegen/plugin-helpers": "^5.0
|
|
69
|
-
"@graphql-codegen/typescript": "^4.
|
|
67
|
+
"@graphql-codegen/cli": "^5.0.5",
|
|
68
|
+
"@graphql-codegen/plugin-helpers": "^5.1.0",
|
|
69
|
+
"@graphql-codegen/typescript": "^4.1.6",
|
|
70
70
|
"@mdi/font": "^7.4.47",
|
|
71
|
-
"@nuxt/kit": "^3.
|
|
71
|
+
"@nuxt/kit": "^3.16.2",
|
|
72
72
|
"@nuxtjs/apollo": "5.0.0-alpha.14",
|
|
73
|
-
"@vue/apollo-composable": "^4.2.
|
|
73
|
+
"@vue/apollo-composable": "^4.2.2",
|
|
74
74
|
"@vuepic/vue-datepicker": "^7.4.1",
|
|
75
|
-
"@vueuse/integrations": "^11.0
|
|
75
|
+
"@vueuse/integrations": "^11.3.0",
|
|
76
76
|
"@zxing/browser": "^0.1.5",
|
|
77
77
|
"cropperjs": "^1.6.2",
|
|
78
78
|
"currency.js": "^2.0.4",
|
|
79
79
|
"exif-rotate-js": "^1.5.0",
|
|
80
|
-
"fuse.js": "^7.
|
|
80
|
+
"fuse.js": "^7.1.0",
|
|
81
81
|
"gql-query-builder": "^3.8.0",
|
|
82
|
-
"graphql": "^16.
|
|
82
|
+
"graphql": "^16.10.0",
|
|
83
|
+
"localstorage-ttl": "^2.0.10",
|
|
83
84
|
"lodash": "^4.17.21",
|
|
84
|
-
"luxon": "^3.
|
|
85
|
+
"luxon": "^3.6.1",
|
|
85
86
|
"maska": "^2.1.11",
|
|
86
|
-
"p-limit": "^6.
|
|
87
|
+
"p-limit": "^6.2.0",
|
|
87
88
|
"painterro": "^1.2.87",
|
|
88
89
|
"pdf-vue3": "^1.0.12",
|
|
89
90
|
"prettier": "3.3.2",
|
|
90
91
|
"print-js": "^1.6.0",
|
|
91
92
|
"uid": "^2.0.2",
|
|
92
|
-
"vue": "^3.5.
|
|
93
|
+
"vue": "^3.5.13",
|
|
93
94
|
"vue-codemirror": "^6.1.1",
|
|
94
95
|
"vue-signature-pad": "^3.0.2",
|
|
95
|
-
"vuetify": "^3.
|
|
96
|
-
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.
|
|
96
|
+
"vuetify": "^3.8.0",
|
|
97
|
+
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
|
|
97
98
|
},
|
|
98
99
|
"devDependencies": {
|
|
99
|
-
"@nuxt/devtools": "^1.
|
|
100
|
-
"@nuxt/eslint-config": "^0.5.
|
|
101
|
-
"@nuxt/module-builder": "^0.8.
|
|
102
|
-
"@nuxt/schema": "^3.
|
|
103
|
-
"@nuxt/test-utils": "^3.
|
|
104
|
-
"@types/
|
|
105
|
-
"@types/
|
|
106
|
-
"@types/
|
|
100
|
+
"@nuxt/devtools": "^1.7.0",
|
|
101
|
+
"@nuxt/eslint-config": "^0.5.7",
|
|
102
|
+
"@nuxt/module-builder": "^0.8.4",
|
|
103
|
+
"@nuxt/schema": "^3.16.2",
|
|
104
|
+
"@nuxt/test-utils": "^3.17.2",
|
|
105
|
+
"@types/crypto-js": "^4.2.2",
|
|
106
|
+
"@types/lodash": "^4.17.16",
|
|
107
|
+
"@types/luxon": "^3.6.2",
|
|
108
|
+
"@types/node": "^18.19.86",
|
|
107
109
|
"@vueuse/core": "^10.11.1",
|
|
108
110
|
"@vueuse/nuxt": "^10.11.1",
|
|
109
|
-
"changelogen": "^0.5.
|
|
110
|
-
"eslint": "^9.
|
|
111
|
-
"nuxt": "^3.
|
|
111
|
+
"changelogen": "^0.5.7",
|
|
112
|
+
"eslint": "^9.23.0",
|
|
113
|
+
"nuxt": "^3.16.2",
|
|
112
114
|
"nuxt-lodash": "^2.5.3",
|
|
113
|
-
"sass": "^1.
|
|
114
|
-
"typescript": "^5.
|
|
115
|
-
"vitest": "^1.6.
|
|
116
|
-
"vue-tsc": "2.
|
|
115
|
+
"sass": "^1.86.3",
|
|
116
|
+
"typescript": "^5.8.2",
|
|
117
|
+
"vitest": "^1.6.1",
|
|
118
|
+
"vue-tsc": "^2.2.10"
|
|
117
119
|
},
|
|
118
120
|
"packageManager": "pnpm@9.15.9+sha512.68046141893c66fad01c079231128e9afb89ef87e2691d69e4d40eee228988295fd4682181bae55b58418c3a253bde65a505ec7c5f9403ece5cc3cd37dcf2531"
|
|
119
121
|
}
|
|
@@ -105,7 +105,7 @@ module.exports = {
|
|
|
105
105
|
|
|
106
106
|
export const scalarType = ${JSON.stringify(scalarType)}
|
|
107
107
|
|
|
108
|
-
function operationCall${'<' + 'T,U>'}(operationType:string, operation: string,fields?: ${'Array' + '<string | Object>'},variables?: U,cache: boolean = false) {
|
|
108
|
+
function operationCall${'<' + 'T,U>'}(operationType:string, operation: string,fields?: ${'Array' + '<string | Object>'},variables?: U,cache: boolean | number = false) {
|
|
109
109
|
return useGraphQlOperation${'<' + 'T>'}(operationType,operation,fields,variables as {[p: string] : any} | undefined,cache)
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -121,7 +121,7 @@ module.exports = {
|
|
|
121
121
|
return operationCall(operationType,name, fields, variables);
|
|
122
122
|
}
|
|
123
123
|
} else {
|
|
124
|
-
returnGraphqlOperation['call'] = async function(fields?: ${'Array' + '<string | Object>'}, variables?: U,cache: boolean = false): Promise${'<' + 'T>'} {
|
|
124
|
+
returnGraphqlOperation['call'] = async function(fields?: ${'Array' + '<string | Object>'}, variables?: U,cache: boolean | number = false): Promise${'<' + 'T>'} {
|
|
125
125
|
return operationCall(operationType,name, fields, variables,cache);
|
|
126
126
|
}
|
|
127
127
|
}
|