@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.js
CHANGED
|
@@ -343,7 +343,13 @@ __name(init, "init");
|
|
|
343
343
|
async function forceFlush() {
|
|
344
344
|
const provider = opentelemetry.trace.getTracerProvider().getDelegate();
|
|
345
345
|
if (provider && provider.forceFlush) {
|
|
346
|
-
|
|
346
|
+
try {
|
|
347
|
+
await provider.forceFlush();
|
|
348
|
+
} catch (err) {
|
|
349
|
+
if (process.env.DEBUG) {
|
|
350
|
+
console.error("tracing forceFlush failed:", err.message);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
347
353
|
}
|
|
348
354
|
}
|
|
349
355
|
__name(forceFlush, "forceFlush");
|
|
@@ -1033,9 +1039,7 @@ var opMapping = {
|
|
|
1033
1039
|
equals: {
|
|
1034
1040
|
op: /* @__PURE__ */ __name((v) => v === null || Array.isArray(v) ? sql2`is not distinct from` : "=", "op")
|
|
1035
1041
|
},
|
|
1036
|
-
notEquals: {
|
|
1037
|
-
op: /* @__PURE__ */ __name((v) => v === null || Array.isArray(v) ? sql2`is distinct from` : "!=", "op")
|
|
1038
|
-
},
|
|
1042
|
+
notEquals: { op: sql2`is distinct from` },
|
|
1039
1043
|
equalsRelative: {
|
|
1040
1044
|
op: sql2`BETWEEN`,
|
|
1041
1045
|
value: /* @__PURE__ */ __name((v) => sql2`${sql2.raw(
|
|
@@ -1797,72 +1801,51 @@ function getApiUrl() {
|
|
|
1797
1801
|
return apiUrl;
|
|
1798
1802
|
}
|
|
1799
1803
|
__name(getApiUrl, "getApiUrl");
|
|
1800
|
-
var Task = class
|
|
1804
|
+
var Task = class {
|
|
1801
1805
|
static {
|
|
1802
1806
|
__name(this, "Task");
|
|
1803
1807
|
}
|
|
1804
1808
|
/**
|
|
1805
|
-
*
|
|
1806
|
-
* @param {string} taskName The name of the task/topic
|
|
1807
|
-
* @param {Object|null} identity Optional identity object for authentication
|
|
1808
|
-
* @param {string|null} authToken Optional auth token for authentication
|
|
1809
|
-
*/
|
|
1810
|
-
constructor(data, taskName, identity = null, authToken = null) {
|
|
1811
|
-
this.id = data.id;
|
|
1812
|
-
this.topic = data.name;
|
|
1813
|
-
this.status = data.status;
|
|
1814
|
-
this.deferredUntil = data.deferredUntil ? new Date(data.deferredUntil) : void 0;
|
|
1815
|
-
this.createdAt = new Date(data.createdAt);
|
|
1816
|
-
this.updatedAt = new Date(data.updatedAt);
|
|
1817
|
-
this.assignedTo = data.assignedTo;
|
|
1818
|
-
this.assignedAt = data.assignedAt ? new Date(data.assignedAt) : void 0;
|
|
1819
|
-
this.resolvedAt = data.resolvedAt ? new Date(data.resolvedAt) : void 0;
|
|
1820
|
-
this.flowRunId = data.flowRunId;
|
|
1821
|
-
this._taskName = taskName;
|
|
1822
|
-
this._identity = identity;
|
|
1823
|
-
this._authToken = authToken;
|
|
1824
|
-
}
|
|
1825
|
-
/**
|
|
1826
|
-
* Returns a new Task instance that will use the given identity for authentication.
|
|
1809
|
+
* Sets the identity for authentication and returns this instance.
|
|
1827
1810
|
* @param {Object} identity The identity object
|
|
1828
|
-
* @returns {Task}
|
|
1811
|
+
* @returns {Task} This Task instance with the identity set
|
|
1829
1812
|
*/
|
|
1830
1813
|
withIdentity(identity) {
|
|
1831
|
-
|
|
1832
|
-
|
|
1814
|
+
this._identity = identity;
|
|
1815
|
+
this._authToken = null;
|
|
1816
|
+
return this;
|
|
1833
1817
|
}
|
|
1834
1818
|
/**
|
|
1835
|
-
*
|
|
1819
|
+
* Sets the auth token for authentication and returns this instance.
|
|
1836
1820
|
* @param {string} token The auth token to use
|
|
1837
|
-
* @returns {Task}
|
|
1821
|
+
* @returns {Task} This Task instance with the auth token set
|
|
1838
1822
|
*/
|
|
1839
1823
|
withAuthToken(token) {
|
|
1840
|
-
|
|
1841
|
-
|
|
1824
|
+
this._identity = null;
|
|
1825
|
+
this._authToken = token;
|
|
1826
|
+
return this;
|
|
1842
1827
|
}
|
|
1843
1828
|
/**
|
|
1844
|
-
*
|
|
1845
|
-
*
|
|
1829
|
+
* Updates the current task instance with data from the API response.
|
|
1830
|
+
* The API returns camelCase fields matching the Go struct JSON tags.
|
|
1831
|
+
* @param {Object} data The API response data
|
|
1846
1832
|
*/
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
resolvedAt: this.resolvedAt?.toISOString(),
|
|
1858
|
-
flowRunId: this.flowRunId
|
|
1859
|
-
};
|
|
1833
|
+
_updateFromResponse(data) {
|
|
1834
|
+
this.id = data.id;
|
|
1835
|
+
this.status = data.status;
|
|
1836
|
+
this.deferredUntil = data.deferredUntil ? new Date(data.deferredUntil) : null;
|
|
1837
|
+
this.createdAt = new Date(data.createdAt);
|
|
1838
|
+
this.updatedAt = new Date(data.updatedAt);
|
|
1839
|
+
this.assignedToId = data.assignedTo ?? null;
|
|
1840
|
+
this.assignedAt = data.assignedAt ? new Date(data.assignedAt) : null;
|
|
1841
|
+
this.resolvedAt = data.resolvedAt ? new Date(data.resolvedAt) : null;
|
|
1842
|
+
this.flowRunId = data.flowRunId ?? null;
|
|
1860
1843
|
}
|
|
1861
1844
|
/**
|
|
1862
1845
|
* Assigns the task to an identity.
|
|
1863
1846
|
* @param {Object} options Options containing identityId
|
|
1864
1847
|
* @param {string} options.identityId The ID of the identity to assign the task to
|
|
1865
|
-
* @returns {Promise<
|
|
1848
|
+
* @returns {Promise<void>}
|
|
1866
1849
|
*/
|
|
1867
1850
|
async assign({ identityId }) {
|
|
1868
1851
|
const name = spanNameForModelAPI(this._taskName, "assign");
|
|
@@ -1881,12 +1864,12 @@ var Task = class _Task {
|
|
|
1881
1864
|
);
|
|
1882
1865
|
}
|
|
1883
1866
|
const result = await response.json();
|
|
1884
|
-
|
|
1867
|
+
this._updateFromResponse(result);
|
|
1885
1868
|
});
|
|
1886
1869
|
}
|
|
1887
1870
|
/**
|
|
1888
1871
|
* Starts the task, creating and running the associated flow.
|
|
1889
|
-
* @returns {Promise<
|
|
1872
|
+
* @returns {Promise<void>}
|
|
1890
1873
|
*/
|
|
1891
1874
|
async start() {
|
|
1892
1875
|
const name = spanNameForModelAPI(this._taskName, "start");
|
|
@@ -1904,12 +1887,12 @@ var Task = class _Task {
|
|
|
1904
1887
|
);
|
|
1905
1888
|
}
|
|
1906
1889
|
const result = await response.json();
|
|
1907
|
-
|
|
1890
|
+
this._updateFromResponse(result);
|
|
1908
1891
|
});
|
|
1909
1892
|
}
|
|
1910
1893
|
/**
|
|
1911
1894
|
* Completes the task.
|
|
1912
|
-
* @returns {Promise<
|
|
1895
|
+
* @returns {Promise<void>}
|
|
1913
1896
|
*/
|
|
1914
1897
|
async complete() {
|
|
1915
1898
|
const name = spanNameForModelAPI(this._taskName, "complete");
|
|
@@ -1927,14 +1910,14 @@ var Task = class _Task {
|
|
|
1927
1910
|
);
|
|
1928
1911
|
}
|
|
1929
1912
|
const result = await response.json();
|
|
1930
|
-
|
|
1913
|
+
this._updateFromResponse(result);
|
|
1931
1914
|
});
|
|
1932
1915
|
}
|
|
1933
1916
|
/**
|
|
1934
1917
|
* Defers the task until a specified date.
|
|
1935
1918
|
* @param {Object} options Options containing deferUntil
|
|
1936
1919
|
* @param {Date} options.deferUntil The date to defer the task until
|
|
1937
|
-
* @returns {Promise<
|
|
1920
|
+
* @returns {Promise<void>}
|
|
1938
1921
|
*/
|
|
1939
1922
|
async defer({ deferUntil }) {
|
|
1940
1923
|
const name = spanNameForModelAPI(this._taskName, "defer");
|
|
@@ -1953,12 +1936,12 @@ var Task = class _Task {
|
|
|
1953
1936
|
);
|
|
1954
1937
|
}
|
|
1955
1938
|
const result = await response.json();
|
|
1956
|
-
|
|
1939
|
+
this._updateFromResponse(result);
|
|
1957
1940
|
});
|
|
1958
1941
|
}
|
|
1959
1942
|
/**
|
|
1960
1943
|
* Cancels the task.
|
|
1961
|
-
* @returns {Promise<
|
|
1944
|
+
* @returns {Promise<void>}
|
|
1962
1945
|
*/
|
|
1963
1946
|
async cancel() {
|
|
1964
1947
|
const name = spanNameForModelAPI(this._taskName, "cancel");
|
|
@@ -1976,7 +1959,30 @@ var Task = class _Task {
|
|
|
1976
1959
|
);
|
|
1977
1960
|
}
|
|
1978
1961
|
const result = await response.json();
|
|
1979
|
-
|
|
1962
|
+
this._updateFromResponse(result);
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Unassigns the task, removing the current assignee.
|
|
1967
|
+
* @returns {Promise<void>}
|
|
1968
|
+
*/
|
|
1969
|
+
async unassign() {
|
|
1970
|
+
const name = spanNameForModelAPI(this._taskName, "unassign");
|
|
1971
|
+
return withSpan(name, async () => {
|
|
1972
|
+
const apiUrl = getApiUrl();
|
|
1973
|
+
const url = `${apiUrl}/topics/json/${this._taskName}/tasks/${this.id}/unassign`;
|
|
1974
|
+
const response = await fetch(url, {
|
|
1975
|
+
method: "PUT",
|
|
1976
|
+
headers: buildHeaders(this._identity, this._authToken)
|
|
1977
|
+
});
|
|
1978
|
+
if (!response.ok) {
|
|
1979
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
1980
|
+
throw new Error(
|
|
1981
|
+
`Failed to unassign task: ${response.status} ${response.statusText} - ${errorBody.message || JSON.stringify(errorBody)}`
|
|
1982
|
+
);
|
|
1983
|
+
}
|
|
1984
|
+
const result = await response.json();
|
|
1985
|
+
this._updateFromResponse(result);
|
|
1980
1986
|
});
|
|
1981
1987
|
}
|
|
1982
1988
|
};
|
|
@@ -1986,13 +1992,17 @@ var TaskAPI = class _TaskAPI {
|
|
|
1986
1992
|
}
|
|
1987
1993
|
/**
|
|
1988
1994
|
* @param {string} taskName The name of the task/topic
|
|
1995
|
+
* @param {Object} tableConfigMap Configuration for table relationships
|
|
1989
1996
|
* @param {Object|null} identity Optional identity object for authentication
|
|
1990
1997
|
* @param {string|null} authToken Optional auth token for authentication
|
|
1991
1998
|
*/
|
|
1992
|
-
constructor(taskName, identity = null, authToken = null) {
|
|
1999
|
+
constructor(taskName, tableConfigMap = {}, identity = null, authToken = null) {
|
|
1993
2000
|
this._taskName = taskName;
|
|
2001
|
+
this._tableName = snakeCase(taskName);
|
|
2002
|
+
this._tableConfigMap = tableConfigMap;
|
|
1994
2003
|
this._identity = identity;
|
|
1995
2004
|
this._authToken = authToken;
|
|
2005
|
+
this._modelAPI = new ModelAPI(this._tableName, null, tableConfigMap);
|
|
1996
2006
|
}
|
|
1997
2007
|
/**
|
|
1998
2008
|
* Returns a new TaskAPI instance that will use the given identity for authentication.
|
|
@@ -2000,7 +2010,7 @@ var TaskAPI = class _TaskAPI {
|
|
|
2000
2010
|
* @returns {TaskAPI} A new TaskAPI instance with the identity set
|
|
2001
2011
|
*/
|
|
2002
2012
|
withIdentity(identity) {
|
|
2003
|
-
return new _TaskAPI(this._taskName, identity, null);
|
|
2013
|
+
return new _TaskAPI(this._taskName, this._tableConfigMap, identity, null);
|
|
2004
2014
|
}
|
|
2005
2015
|
/**
|
|
2006
2016
|
* Returns a new TaskAPI instance that will use the given auth token for authentication.
|
|
@@ -2008,13 +2018,14 @@ var TaskAPI = class _TaskAPI {
|
|
|
2008
2018
|
* @returns {TaskAPI} A new TaskAPI instance with the auth token set
|
|
2009
2019
|
*/
|
|
2010
2020
|
withAuthToken(token) {
|
|
2011
|
-
return new _TaskAPI(this._taskName, null, token);
|
|
2021
|
+
return new _TaskAPI(this._taskName, this._tableConfigMap, null, token);
|
|
2012
2022
|
}
|
|
2013
2023
|
/**
|
|
2014
2024
|
* Creates a new task with the given data by calling the tasks API.
|
|
2025
|
+
* After creation, fetches the full task data from the database to include all fields.
|
|
2015
2026
|
* @param {Object} data The task data fields
|
|
2016
2027
|
* @param {Object} options Optional settings like deferredUntil
|
|
2017
|
-
* @returns {Promise<Task>} The created task
|
|
2028
|
+
* @returns {Promise<Task>} The created task with all fields
|
|
2018
2029
|
*/
|
|
2019
2030
|
async create(data = {}, options = {}) {
|
|
2020
2031
|
const name = spanNameForModelAPI(this._taskName, "create");
|
|
@@ -2039,9 +2050,46 @@ var TaskAPI = class _TaskAPI {
|
|
|
2039
2050
|
);
|
|
2040
2051
|
}
|
|
2041
2052
|
const result = await response.json();
|
|
2042
|
-
|
|
2053
|
+
const task = await this.findOne({ id: result.id });
|
|
2054
|
+
if (!task) {
|
|
2055
|
+
throw new Error(`Failed to fetch created task with id: ${result.id}`);
|
|
2056
|
+
}
|
|
2057
|
+
return task;
|
|
2043
2058
|
});
|
|
2044
2059
|
}
|
|
2060
|
+
/**
|
|
2061
|
+
* Wraps an entity with Task methods by setting its prototype and adding required fields.
|
|
2062
|
+
* @param {Object} entity The entity from ModelAPI
|
|
2063
|
+
* @returns {Task} The entity with Task methods
|
|
2064
|
+
*/
|
|
2065
|
+
_wrapAsTask(entity) {
|
|
2066
|
+
if (!entity) return null;
|
|
2067
|
+
entity._taskName = this._taskName;
|
|
2068
|
+
entity._identity = this._identity;
|
|
2069
|
+
entity._authToken = this._authToken;
|
|
2070
|
+
Object.setPrototypeOf(entity, Task.prototype);
|
|
2071
|
+
return entity;
|
|
2072
|
+
}
|
|
2073
|
+
/**
|
|
2074
|
+
* Finds a single task matching the given conditions.
|
|
2075
|
+
* Returns a Task instance with both entity fields and action methods.
|
|
2076
|
+
* @param {Object} where Conditions to match
|
|
2077
|
+
* @returns {Promise<Task|null>} The Task instance or null if not found
|
|
2078
|
+
*/
|
|
2079
|
+
async findOne(where = {}) {
|
|
2080
|
+
const entity = await this._modelAPI.findOne(where);
|
|
2081
|
+
return this._wrapAsTask(entity);
|
|
2082
|
+
}
|
|
2083
|
+
/**
|
|
2084
|
+
* Finds multiple tasks matching the given conditions.
|
|
2085
|
+
* Returns Task instances with both entity fields and action methods.
|
|
2086
|
+
* @param {Object} params Query parameters including where, limit, offset, orderBy
|
|
2087
|
+
* @returns {Promise<Array<Task>>} Array of Task instances
|
|
2088
|
+
*/
|
|
2089
|
+
async findMany(params = {}) {
|
|
2090
|
+
const entities = await this._modelAPI.findMany(params);
|
|
2091
|
+
return entities.map((entity) => this._wrapAsTask(entity));
|
|
2092
|
+
}
|
|
2045
2093
|
};
|
|
2046
2094
|
|
|
2047
2095
|
// src/FlowsAPI.js
|