@teamkeel/functions-runtime 0.430.0 → 0.432.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/index.cjs +112 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -42
- package/dist/index.d.ts +68 -42
- package/dist/index.js +112 -64
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -399,7 +399,13 @@ __name(init, "init");
|
|
|
399
399
|
async function forceFlush() {
|
|
400
400
|
const provider = opentelemetry.trace.getTracerProvider().getDelegate();
|
|
401
401
|
if (provider && provider.forceFlush) {
|
|
402
|
-
|
|
402
|
+
try {
|
|
403
|
+
await provider.forceFlush();
|
|
404
|
+
} catch (err) {
|
|
405
|
+
if (process.env.DEBUG) {
|
|
406
|
+
console.error("tracing forceFlush failed:", err.message);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
403
409
|
}
|
|
404
410
|
}
|
|
405
411
|
__name(forceFlush, "forceFlush");
|
|
@@ -1085,9 +1091,7 @@ var opMapping = {
|
|
|
1085
1091
|
equals: {
|
|
1086
1092
|
op: /* @__PURE__ */ __name((v) => v === null || Array.isArray(v) ? import_kysely4.sql`is not distinct from` : "=", "op")
|
|
1087
1093
|
},
|
|
1088
|
-
notEquals: {
|
|
1089
|
-
op: /* @__PURE__ */ __name((v) => v === null || Array.isArray(v) ? import_kysely4.sql`is distinct from` : "!=", "op")
|
|
1090
|
-
},
|
|
1094
|
+
notEquals: { op: import_kysely4.sql`is distinct from` },
|
|
1091
1095
|
equalsRelative: {
|
|
1092
1096
|
op: import_kysely4.sql`BETWEEN`,
|
|
1093
1097
|
value: /* @__PURE__ */ __name((v) => import_kysely4.sql`${import_kysely4.sql.raw(
|
|
@@ -1849,72 +1853,51 @@ function getApiUrl() {
|
|
|
1849
1853
|
return apiUrl;
|
|
1850
1854
|
}
|
|
1851
1855
|
__name(getApiUrl, "getApiUrl");
|
|
1852
|
-
var Task = class
|
|
1856
|
+
var Task = class {
|
|
1853
1857
|
static {
|
|
1854
1858
|
__name(this, "Task");
|
|
1855
1859
|
}
|
|
1856
1860
|
/**
|
|
1857
|
-
*
|
|
1858
|
-
* @param {string} taskName The name of the task/topic
|
|
1859
|
-
* @param {Object|null} identity Optional identity object for authentication
|
|
1860
|
-
* @param {string|null} authToken Optional auth token for authentication
|
|
1861
|
-
*/
|
|
1862
|
-
constructor(data, taskName, identity = null, authToken = null) {
|
|
1863
|
-
this.id = data.id;
|
|
1864
|
-
this.topic = data.name;
|
|
1865
|
-
this.status = data.status;
|
|
1866
|
-
this.deferredUntil = data.deferredUntil ? new Date(data.deferredUntil) : void 0;
|
|
1867
|
-
this.createdAt = new Date(data.createdAt);
|
|
1868
|
-
this.updatedAt = new Date(data.updatedAt);
|
|
1869
|
-
this.assignedTo = data.assignedTo;
|
|
1870
|
-
this.assignedAt = data.assignedAt ? new Date(data.assignedAt) : void 0;
|
|
1871
|
-
this.resolvedAt = data.resolvedAt ? new Date(data.resolvedAt) : void 0;
|
|
1872
|
-
this.flowRunId = data.flowRunId;
|
|
1873
|
-
this._taskName = taskName;
|
|
1874
|
-
this._identity = identity;
|
|
1875
|
-
this._authToken = authToken;
|
|
1876
|
-
}
|
|
1877
|
-
/**
|
|
1878
|
-
* Returns a new Task instance that will use the given identity for authentication.
|
|
1861
|
+
* Sets the identity for authentication and returns this instance.
|
|
1879
1862
|
* @param {Object} identity The identity object
|
|
1880
|
-
* @returns {Task}
|
|
1863
|
+
* @returns {Task} This Task instance with the identity set
|
|
1881
1864
|
*/
|
|
1882
1865
|
withIdentity(identity) {
|
|
1883
|
-
|
|
1884
|
-
|
|
1866
|
+
this._identity = identity;
|
|
1867
|
+
this._authToken = null;
|
|
1868
|
+
return this;
|
|
1885
1869
|
}
|
|
1886
1870
|
/**
|
|
1887
|
-
*
|
|
1871
|
+
* Sets the auth token for authentication and returns this instance.
|
|
1888
1872
|
* @param {string} token The auth token to use
|
|
1889
|
-
* @returns {Task}
|
|
1873
|
+
* @returns {Task} This Task instance with the auth token set
|
|
1890
1874
|
*/
|
|
1891
1875
|
withAuthToken(token) {
|
|
1892
|
-
|
|
1893
|
-
|
|
1876
|
+
this._identity = null;
|
|
1877
|
+
this._authToken = token;
|
|
1878
|
+
return this;
|
|
1894
1879
|
}
|
|
1895
1880
|
/**
|
|
1896
|
-
*
|
|
1897
|
-
*
|
|
1881
|
+
* Updates the current task instance with data from the API response.
|
|
1882
|
+
* The API returns camelCase fields matching the Go struct JSON tags.
|
|
1883
|
+
* @param {Object} data The API response data
|
|
1898
1884
|
*/
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
resolvedAt: this.resolvedAt?.toISOString(),
|
|
1910
|
-
flowRunId: this.flowRunId
|
|
1911
|
-
};
|
|
1885
|
+
_updateFromResponse(data) {
|
|
1886
|
+
this.id = data.id;
|
|
1887
|
+
this.status = data.status;
|
|
1888
|
+
this.deferredUntil = data.deferredUntil ? new Date(data.deferredUntil) : null;
|
|
1889
|
+
this.createdAt = new Date(data.createdAt);
|
|
1890
|
+
this.updatedAt = new Date(data.updatedAt);
|
|
1891
|
+
this.assignedToId = data.assignedTo ?? null;
|
|
1892
|
+
this.assignedAt = data.assignedAt ? new Date(data.assignedAt) : null;
|
|
1893
|
+
this.resolvedAt = data.resolvedAt ? new Date(data.resolvedAt) : null;
|
|
1894
|
+
this.flowRunId = data.flowRunId ?? null;
|
|
1912
1895
|
}
|
|
1913
1896
|
/**
|
|
1914
1897
|
* Assigns the task to an identity.
|
|
1915
1898
|
* @param {Object} options Options containing identityId
|
|
1916
1899
|
* @param {string} options.identityId The ID of the identity to assign the task to
|
|
1917
|
-
* @returns {Promise<
|
|
1900
|
+
* @returns {Promise<void>}
|
|
1918
1901
|
*/
|
|
1919
1902
|
async assign({ identityId }) {
|
|
1920
1903
|
const name = spanNameForModelAPI(this._taskName, "assign");
|
|
@@ -1933,12 +1916,12 @@ var Task = class _Task {
|
|
|
1933
1916
|
);
|
|
1934
1917
|
}
|
|
1935
1918
|
const result = await response.json();
|
|
1936
|
-
|
|
1919
|
+
this._updateFromResponse(result);
|
|
1937
1920
|
});
|
|
1938
1921
|
}
|
|
1939
1922
|
/**
|
|
1940
1923
|
* Starts the task, creating and running the associated flow.
|
|
1941
|
-
* @returns {Promise<
|
|
1924
|
+
* @returns {Promise<void>}
|
|
1942
1925
|
*/
|
|
1943
1926
|
async start() {
|
|
1944
1927
|
const name = spanNameForModelAPI(this._taskName, "start");
|
|
@@ -1956,12 +1939,12 @@ var Task = class _Task {
|
|
|
1956
1939
|
);
|
|
1957
1940
|
}
|
|
1958
1941
|
const result = await response.json();
|
|
1959
|
-
|
|
1942
|
+
this._updateFromResponse(result);
|
|
1960
1943
|
});
|
|
1961
1944
|
}
|
|
1962
1945
|
/**
|
|
1963
1946
|
* Completes the task.
|
|
1964
|
-
* @returns {Promise<
|
|
1947
|
+
* @returns {Promise<void>}
|
|
1965
1948
|
*/
|
|
1966
1949
|
async complete() {
|
|
1967
1950
|
const name = spanNameForModelAPI(this._taskName, "complete");
|
|
@@ -1979,14 +1962,14 @@ var Task = class _Task {
|
|
|
1979
1962
|
);
|
|
1980
1963
|
}
|
|
1981
1964
|
const result = await response.json();
|
|
1982
|
-
|
|
1965
|
+
this._updateFromResponse(result);
|
|
1983
1966
|
});
|
|
1984
1967
|
}
|
|
1985
1968
|
/**
|
|
1986
1969
|
* Defers the task until a specified date.
|
|
1987
1970
|
* @param {Object} options Options containing deferUntil
|
|
1988
1971
|
* @param {Date} options.deferUntil The date to defer the task until
|
|
1989
|
-
* @returns {Promise<
|
|
1972
|
+
* @returns {Promise<void>}
|
|
1990
1973
|
*/
|
|
1991
1974
|
async defer({ deferUntil }) {
|
|
1992
1975
|
const name = spanNameForModelAPI(this._taskName, "defer");
|
|
@@ -2005,12 +1988,12 @@ var Task = class _Task {
|
|
|
2005
1988
|
);
|
|
2006
1989
|
}
|
|
2007
1990
|
const result = await response.json();
|
|
2008
|
-
|
|
1991
|
+
this._updateFromResponse(result);
|
|
2009
1992
|
});
|
|
2010
1993
|
}
|
|
2011
1994
|
/**
|
|
2012
1995
|
* Cancels the task.
|
|
2013
|
-
* @returns {Promise<
|
|
1996
|
+
* @returns {Promise<void>}
|
|
2014
1997
|
*/
|
|
2015
1998
|
async cancel() {
|
|
2016
1999
|
const name = spanNameForModelAPI(this._taskName, "cancel");
|
|
@@ -2028,7 +2011,30 @@ var Task = class _Task {
|
|
|
2028
2011
|
);
|
|
2029
2012
|
}
|
|
2030
2013
|
const result = await response.json();
|
|
2031
|
-
|
|
2014
|
+
this._updateFromResponse(result);
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
/**
|
|
2018
|
+
* Unassigns the task, removing the current assignee.
|
|
2019
|
+
* @returns {Promise<void>}
|
|
2020
|
+
*/
|
|
2021
|
+
async unassign() {
|
|
2022
|
+
const name = spanNameForModelAPI(this._taskName, "unassign");
|
|
2023
|
+
return withSpan(name, async () => {
|
|
2024
|
+
const apiUrl = getApiUrl();
|
|
2025
|
+
const url = `${apiUrl}/topics/json/${this._taskName}/tasks/${this.id}/unassign`;
|
|
2026
|
+
const response = await fetch(url, {
|
|
2027
|
+
method: "PUT",
|
|
2028
|
+
headers: buildHeaders(this._identity, this._authToken)
|
|
2029
|
+
});
|
|
2030
|
+
if (!response.ok) {
|
|
2031
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
2032
|
+
throw new Error(
|
|
2033
|
+
`Failed to unassign task: ${response.status} ${response.statusText} - ${errorBody.message || JSON.stringify(errorBody)}`
|
|
2034
|
+
);
|
|
2035
|
+
}
|
|
2036
|
+
const result = await response.json();
|
|
2037
|
+
this._updateFromResponse(result);
|
|
2032
2038
|
});
|
|
2033
2039
|
}
|
|
2034
2040
|
};
|
|
@@ -2038,13 +2044,17 @@ var TaskAPI = class _TaskAPI {
|
|
|
2038
2044
|
}
|
|
2039
2045
|
/**
|
|
2040
2046
|
* @param {string} taskName The name of the task/topic
|
|
2047
|
+
* @param {Object} tableConfigMap Configuration for table relationships
|
|
2041
2048
|
* @param {Object|null} identity Optional identity object for authentication
|
|
2042
2049
|
* @param {string|null} authToken Optional auth token for authentication
|
|
2043
2050
|
*/
|
|
2044
|
-
constructor(taskName, identity = null, authToken = null) {
|
|
2051
|
+
constructor(taskName, tableConfigMap = {}, identity = null, authToken = null) {
|
|
2045
2052
|
this._taskName = taskName;
|
|
2053
|
+
this._tableName = (0, import_change_case.snakeCase)(taskName);
|
|
2054
|
+
this._tableConfigMap = tableConfigMap;
|
|
2046
2055
|
this._identity = identity;
|
|
2047
2056
|
this._authToken = authToken;
|
|
2057
|
+
this._modelAPI = new ModelAPI(this._tableName, null, tableConfigMap);
|
|
2048
2058
|
}
|
|
2049
2059
|
/**
|
|
2050
2060
|
* Returns a new TaskAPI instance that will use the given identity for authentication.
|
|
@@ -2052,7 +2062,7 @@ var TaskAPI = class _TaskAPI {
|
|
|
2052
2062
|
* @returns {TaskAPI} A new TaskAPI instance with the identity set
|
|
2053
2063
|
*/
|
|
2054
2064
|
withIdentity(identity) {
|
|
2055
|
-
return new _TaskAPI(this._taskName, identity, null);
|
|
2065
|
+
return new _TaskAPI(this._taskName, this._tableConfigMap, identity, null);
|
|
2056
2066
|
}
|
|
2057
2067
|
/**
|
|
2058
2068
|
* Returns a new TaskAPI instance that will use the given auth token for authentication.
|
|
@@ -2060,13 +2070,14 @@ var TaskAPI = class _TaskAPI {
|
|
|
2060
2070
|
* @returns {TaskAPI} A new TaskAPI instance with the auth token set
|
|
2061
2071
|
*/
|
|
2062
2072
|
withAuthToken(token) {
|
|
2063
|
-
return new _TaskAPI(this._taskName, null, token);
|
|
2073
|
+
return new _TaskAPI(this._taskName, this._tableConfigMap, null, token);
|
|
2064
2074
|
}
|
|
2065
2075
|
/**
|
|
2066
2076
|
* Creates a new task with the given data by calling the tasks API.
|
|
2077
|
+
* After creation, fetches the full task data from the database to include all fields.
|
|
2067
2078
|
* @param {Object} data The task data fields
|
|
2068
2079
|
* @param {Object} options Optional settings like deferredUntil
|
|
2069
|
-
* @returns {Promise<Task>} The created task
|
|
2080
|
+
* @returns {Promise<Task>} The created task with all fields
|
|
2070
2081
|
*/
|
|
2071
2082
|
async create(data = {}, options = {}) {
|
|
2072
2083
|
const name = spanNameForModelAPI(this._taskName, "create");
|
|
@@ -2091,9 +2102,46 @@ var TaskAPI = class _TaskAPI {
|
|
|
2091
2102
|
);
|
|
2092
2103
|
}
|
|
2093
2104
|
const result = await response.json();
|
|
2094
|
-
|
|
2105
|
+
const task = await this.findOne({ id: result.id });
|
|
2106
|
+
if (!task) {
|
|
2107
|
+
throw new Error(`Failed to fetch created task with id: ${result.id}`);
|
|
2108
|
+
}
|
|
2109
|
+
return task;
|
|
2095
2110
|
});
|
|
2096
2111
|
}
|
|
2112
|
+
/**
|
|
2113
|
+
* Wraps an entity with Task methods by setting its prototype and adding required fields.
|
|
2114
|
+
* @param {Object} entity The entity from ModelAPI
|
|
2115
|
+
* @returns {Task} The entity with Task methods
|
|
2116
|
+
*/
|
|
2117
|
+
_wrapAsTask(entity) {
|
|
2118
|
+
if (!entity) return null;
|
|
2119
|
+
entity._taskName = this._taskName;
|
|
2120
|
+
entity._identity = this._identity;
|
|
2121
|
+
entity._authToken = this._authToken;
|
|
2122
|
+
Object.setPrototypeOf(entity, Task.prototype);
|
|
2123
|
+
return entity;
|
|
2124
|
+
}
|
|
2125
|
+
/**
|
|
2126
|
+
* Finds a single task matching the given conditions.
|
|
2127
|
+
* Returns a Task instance with both entity fields and action methods.
|
|
2128
|
+
* @param {Object} where Conditions to match
|
|
2129
|
+
* @returns {Promise<Task|null>} The Task instance or null if not found
|
|
2130
|
+
*/
|
|
2131
|
+
async findOne(where = {}) {
|
|
2132
|
+
const entity = await this._modelAPI.findOne(where);
|
|
2133
|
+
return this._wrapAsTask(entity);
|
|
2134
|
+
}
|
|
2135
|
+
/**
|
|
2136
|
+
* Finds multiple tasks matching the given conditions.
|
|
2137
|
+
* Returns Task instances with both entity fields and action methods.
|
|
2138
|
+
* @param {Object} params Query parameters including where, limit, offset, orderBy
|
|
2139
|
+
* @returns {Promise<Array<Task>>} Array of Task instances
|
|
2140
|
+
*/
|
|
2141
|
+
async findMany(params = {}) {
|
|
2142
|
+
const entities = await this._modelAPI.findMany(params);
|
|
2143
|
+
return entities.map((entity) => this._wrapAsTask(entity));
|
|
2144
|
+
}
|
|
2097
2145
|
};
|
|
2098
2146
|
|
|
2099
2147
|
// src/FlowsAPI.js
|