@konomi-app/kintone-utilities 1.13.0 → 1.14.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/dist/api-types.d.ts +8 -8
- package/dist/rest-api.d.ts +32 -5
- package/dist/rest-api.js +54 -4
- package/dist/rest-api.js.map +1 -1
- package/package.json +1 -1
package/dist/api-types.d.ts
CHANGED
|
@@ -120,14 +120,6 @@ export declare namespace kintoneAPI {
|
|
|
120
120
|
readonly fields?: FieldProperties;
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
-
/**
|
|
124
|
-
* @deprecated Use `kintoneAPI.js.EventType` instead.
|
|
125
|
-
*/
|
|
126
|
-
type EventType = kintoneAPI.js.EventType;
|
|
127
|
-
/**
|
|
128
|
-
* @deprecated Use `kintoneAPI.js.Event` instead.
|
|
129
|
-
*/
|
|
130
|
-
type Event<T = RecordData> = kintoneAPI.js.Event<T>;
|
|
131
123
|
namespace js {
|
|
132
124
|
type Event<T = RecordData> = {
|
|
133
125
|
appId: number;
|
|
@@ -173,4 +165,12 @@ export declare namespace kintoneAPI {
|
|
|
173
165
|
type EventType = 'portal.show' | 'app.record.index.show' | 'app.record.index.edit.show' | 'app.record.index.edit.submit' | 'app.record.index.edit.submit.success' | 'app.record.index.delete.submit' | 'app.record.detail.show' | 'app.record.detail.delete.submit' | 'app.record.detail.process.proceed' | 'app.record.create.show' | 'app.record.create.change' | 'app.record.create.submit' | 'app.record.create.submit.success' | 'app.record.edit.show' | 'app.record.edit.change' | 'app.record.edit.submit' | 'app.record.edit.submit.success' | 'app.record.print.show' | 'mobile.app.record.index.show' | 'mobile.app.record.detail.show' | 'mobile.app.record.detail.delete.submit' | 'mobile.app.record.detail.process.proceed' | 'mobile.app.record.create.show' | 'mobile.app.record.create.change' | 'mobile.app.record.create.submit' | 'mobile.app.record.create.submit.success' | 'mobile.app.record.edit.show' | 'mobile.app.record.edit.change' | 'mobile.app.record.edit.submit' | 'mobile.app.record.edit.submit.success';
|
|
174
166
|
}
|
|
175
167
|
namespace rest { }
|
|
168
|
+
/**
|
|
169
|
+
* @deprecated Use `kintoneAPI.js.EventType` instead.
|
|
170
|
+
*/
|
|
171
|
+
type EventType = kintoneAPI.js.EventType;
|
|
172
|
+
/**
|
|
173
|
+
* @deprecated Use `kintoneAPI.js.Event` instead.
|
|
174
|
+
*/
|
|
175
|
+
type Event<T = RecordData> = kintoneAPI.js.Event<T>;
|
|
176
176
|
}
|
package/dist/rest-api.d.ts
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
app:
|
|
1
|
+
import { kintoneAPI } from './api-types';
|
|
2
|
+
type App = number | string;
|
|
3
|
+
export declare const getAllRecords: <T extends Record<string, any> = import("@kintone/rest-api-client/lib/client/types").Record>(props: {
|
|
4
|
+
app: App;
|
|
5
|
+
query?: string | undefined;
|
|
5
6
|
fields?: string[] | undefined;
|
|
6
|
-
onStep?:
|
|
7
|
+
onStep?: OnStep<T> | undefined;
|
|
8
|
+
}) => Promise<T[]>;
|
|
9
|
+
type WithId<T> = T & {
|
|
10
|
+
$id: kintoneAPI.field.ID;
|
|
11
|
+
};
|
|
12
|
+
type OnStep<T> = (records: T[]) => void;
|
|
13
|
+
export declare const getAllRecordsWithId: <T extends Record<string, any>>(props: {
|
|
14
|
+
app: App;
|
|
15
|
+
fields?: string[] | undefined;
|
|
16
|
+
onStep?: OnStep<T> | undefined;
|
|
7
17
|
condition?: string | undefined;
|
|
18
|
+
}) => Promise<WithId<T>[]>;
|
|
19
|
+
type OnTotalGet = (total: number) => void;
|
|
20
|
+
export declare const getAllRecordsWithCursor: <T extends Record<string, any>>(props: {
|
|
21
|
+
app: App;
|
|
22
|
+
fields?: string[] | undefined;
|
|
23
|
+
query?: string | undefined;
|
|
24
|
+
onTotalGet?: OnTotalGet | undefined;
|
|
25
|
+
onStep?: OnStep<T> | undefined;
|
|
8
26
|
}) => Promise<T[]>;
|
|
27
|
+
export declare const uploadFile: (props: {
|
|
28
|
+
file: {
|
|
29
|
+
name: string;
|
|
30
|
+
data: Blob;
|
|
31
|
+
};
|
|
32
|
+
}) => Promise<{
|
|
33
|
+
fileKey: string;
|
|
34
|
+
}>;
|
|
35
|
+
export {};
|
package/dist/rest-api.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
const
|
|
1
|
+
const API_ENDPOINT_ROOT = '/k/v1';
|
|
2
|
+
const API_LIMIT = {
|
|
3
|
+
GET: 500,
|
|
4
|
+
};
|
|
5
|
+
export const getAllRecords = async (props) => {
|
|
6
|
+
if (props.query && props.query.includes('order by')) {
|
|
7
|
+
return getAllRecordsWithCursor(props);
|
|
8
|
+
}
|
|
9
|
+
return getAllRecordsWithId(props);
|
|
10
|
+
};
|
|
2
11
|
export const getAllRecordsWithId = async (props) => {
|
|
12
|
+
checkBrowser();
|
|
3
13
|
const { fields: initFields, condition: initCondition = '' } = props;
|
|
4
14
|
const fields = initFields?.length ? [...new Set([...initFields, '$id'])] : undefined;
|
|
5
15
|
// order byは使用できないため、conditionに含まれている場合は除外する
|
|
@@ -9,8 +19,8 @@ export const getAllRecordsWithId = async (props) => {
|
|
|
9
19
|
const getRecursive = async (props) => {
|
|
10
20
|
const { app, fields, condition, id } = props;
|
|
11
21
|
const newCondition = id ? `${condition ? `${condition} and ` : ''} $id < ${id}` : condition;
|
|
12
|
-
const query = `${newCondition} order by $id desc limit ${
|
|
13
|
-
const { records } = await kintone.api(kintone.api.url(
|
|
22
|
+
const query = `${newCondition} order by $id desc limit ${API_LIMIT.GET}`;
|
|
23
|
+
const { records } = await kintone.api(kintone.api.url(`${API_ENDPOINT_ROOT}/records`, true), 'GET', {
|
|
14
24
|
app,
|
|
15
25
|
fields,
|
|
16
26
|
query,
|
|
@@ -24,6 +34,46 @@ const getRecursive = async (props) => {
|
|
|
24
34
|
}
|
|
25
35
|
const lastRecord = stored[stored.length - 1];
|
|
26
36
|
const lastId = lastRecord.$id.value;
|
|
27
|
-
return records.length ===
|
|
37
|
+
return records.length === API_LIMIT.GET ? getRecursive({ ...props, id: lastId, stored }) : stored;
|
|
38
|
+
};
|
|
39
|
+
export const getAllRecordsWithCursor = async (props) => {
|
|
40
|
+
checkBrowser();
|
|
41
|
+
const { app, fields = [], query = '', onTotalGet = null, onStep = null } = props;
|
|
42
|
+
const param = { app, fields, size: API_LIMIT.GET, query };
|
|
43
|
+
const cursor = await kintone.api(kintone.api.url(`${API_ENDPOINT_ROOT}/cursor`, true), 'POST', param);
|
|
44
|
+
if (onTotalGet) {
|
|
45
|
+
onTotalGet(cursor.totalCount);
|
|
46
|
+
}
|
|
47
|
+
return getRecordsByCursorId({ id: cursor.id, onStep });
|
|
48
|
+
};
|
|
49
|
+
const getRecordsByCursorId = async (props) => {
|
|
50
|
+
const { id, onStep, loadedData = [] } = props;
|
|
51
|
+
const response = await kintone.api(kintone.api.url(`${API_ENDPOINT_ROOT}/cursor`, true), 'GET', {
|
|
52
|
+
id,
|
|
53
|
+
});
|
|
54
|
+
const newRecords = [...loadedData, ...response.records];
|
|
55
|
+
if (onStep) {
|
|
56
|
+
onStep(newRecords);
|
|
57
|
+
}
|
|
58
|
+
return response.next ? getRecordsByCursorId({ id, onStep, loadedData: newRecords }) : newRecords;
|
|
59
|
+
};
|
|
60
|
+
export const uploadFile = async (props) => {
|
|
61
|
+
checkBrowser();
|
|
62
|
+
const { file } = props;
|
|
63
|
+
const formData = new FormData();
|
|
64
|
+
formData.append('__REQUEST_TOKEN__', kintone.getRequestToken());
|
|
65
|
+
formData.append('file', file.data, file.name);
|
|
66
|
+
const headers = { 'X-Requested-With': 'XMLHttpRequest' };
|
|
67
|
+
const response = await fetch('/k/v1/file.json', {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers,
|
|
70
|
+
body: formData,
|
|
71
|
+
});
|
|
72
|
+
return response.json();
|
|
73
|
+
};
|
|
74
|
+
const checkBrowser = () => {
|
|
75
|
+
if (typeof window === 'undefined') {
|
|
76
|
+
throw new Error('この関数はブラウザでのみ使用できます');
|
|
77
|
+
}
|
|
28
78
|
};
|
|
29
79
|
//# sourceMappingURL=rest-api.js.map
|
package/dist/rest-api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-api.js","sourceRoot":"","sources":["../src/rest-api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rest-api.js","sourceRoot":"","sources":["../src/rest-api.ts"],"names":[],"mappings":"AAGA,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAClC,MAAM,SAAS,GAAG;IAChB,GAAG,EAAE,GAAG;CACT,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAyD,KAK1F,EAAE,EAAE;IACH,IAAI,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACnD,OAAO,uBAAuB,CAAI,KAAK,CAAC,CAAC;KAC1C;IACD,OAAO,mBAAmB,CAAI,KAAK,CAAC,CAAC;AACvC,CAAC,CAAC;AAKF,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAiC,KAKxE,EAAwB,EAAE;IACzB,YAAY,EAAE,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC;IAEpE,MAAM,MAAM,GAAG,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAErF,4CAA4C;IAC5C,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;IAE3D,OAAO,YAAY,CAAI,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC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