jazz-tools 0.18.27 → 0.18.28

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.
Files changed (40) hide show
  1. package/.turbo/turbo-build.log +57 -57
  2. package/CHANGELOG.md +13 -0
  3. package/dist/{chunk-ZIAN4UY5.js → chunk-YOL3XDDW.js} +158 -120
  4. package/dist/chunk-YOL3XDDW.js.map +1 -0
  5. package/dist/index.js +1 -1
  6. package/dist/react-core/hooks.d.ts +4 -0
  7. package/dist/react-core/hooks.d.ts.map +1 -1
  8. package/dist/react-core/index.js +5 -0
  9. package/dist/react-core/index.js.map +1 -1
  10. package/dist/testing.js +1 -1
  11. package/dist/tools/coValues/coList.d.ts +11 -3
  12. package/dist/tools/coValues/coList.d.ts.map +1 -1
  13. package/dist/tools/coValues/coMap.d.ts +21 -5
  14. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  15. package/dist/tools/coValues/group.d.ts +2 -2
  16. package/dist/tools/coValues/group.d.ts.map +1 -1
  17. package/dist/tools/coValues/inbox.d.ts.map +1 -1
  18. package/dist/tools/coValues/interfaces.d.ts +9 -0
  19. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  20. package/dist/tools/exports.d.ts +1 -1
  21. package/dist/tools/exports.d.ts.map +1 -1
  22. package/dist/tools/tests/coList.unique.test.d.ts +2 -0
  23. package/dist/tools/tests/coList.unique.test.d.ts.map +1 -0
  24. package/dist/tools/tests/coMap.unique.test.d.ts +2 -0
  25. package/dist/tools/tests/coMap.unique.test.d.ts.map +1 -0
  26. package/package.json +4 -4
  27. package/src/react-core/hooks.ts +8 -0
  28. package/src/react-core/tests/useAccount.test.ts +61 -1
  29. package/src/react-core/tests/usePassPhraseAuth.test.ts +74 -2
  30. package/src/tools/coValues/coList.ts +38 -35
  31. package/src/tools/coValues/coMap.ts +38 -38
  32. package/src/tools/coValues/group.ts +5 -1
  33. package/src/tools/coValues/inbox.ts +4 -3
  34. package/src/tools/coValues/interfaces.ts +88 -0
  35. package/src/tools/exports.ts +1 -0
  36. package/src/tools/tests/coList.test.ts +0 -190
  37. package/src/tools/tests/coList.unique.test.ts +244 -0
  38. package/src/tools/tests/coMap.test.ts +0 -433
  39. package/src/tools/tests/coMap.unique.test.ts +474 -0
  40. package/dist/chunk-ZIAN4UY5.js.map +0 -1
@@ -1833,439 +1833,6 @@ describe("CoMap Typescript validation", async () => {
1833
1833
 
1834
1834
  expect(loadedMap).not.toBe("unavailable");
1835
1835
  });
1836
- });
1837
-
1838
- describe("Creating and finding unique CoMaps", async () => {
1839
- test("Creating and finding unique CoMaps", async () => {
1840
- const group = Group.create();
1841
-
1842
- const Person = co.map({
1843
- name: z.string(),
1844
- _height: z.number(),
1845
- birthday: z.date(),
1846
- color: z.string(),
1847
- });
1848
-
1849
- const alice = Person.create(
1850
- {
1851
- name: "Alice",
1852
- _height: 100,
1853
- birthday: new Date("1990-01-01"),
1854
- color: "red",
1855
- },
1856
- { owner: group, unique: { name: "Alice" } },
1857
- );
1858
-
1859
- const foundAlice = await Person.loadUnique(
1860
- { name: "Alice" },
1861
- group.$jazz.id,
1862
- );
1863
- expect(foundAlice).toEqual(alice);
1864
- });
1865
-
1866
- test("manual upserting pattern", async () => {
1867
- // Schema
1868
- const Event = co.map({
1869
- title: z.string(),
1870
- identifier: z.string(),
1871
- external_id: z.string(),
1872
- });
1873
-
1874
- // Data
1875
- const sourceData = {
1876
- title: "Test Event Title",
1877
- identifier: "test-event-identifier",
1878
- _id: "test-event-external-id",
1879
- };
1880
- const workspace = Group.create();
1881
-
1882
- // Pattern
1883
- let activeEvent = await Event.loadUnique(
1884
- { identifier: sourceData.identifier },
1885
- workspace.$jazz.id,
1886
- );
1887
- if (!activeEvent) {
1888
- activeEvent = Event.create(
1889
- {
1890
- title: sourceData.title,
1891
- identifier: sourceData.identifier,
1892
- external_id: sourceData._id,
1893
- },
1894
- workspace,
1895
- );
1896
- } else {
1897
- activeEvent.$jazz.applyDiff({
1898
- title: sourceData.title,
1899
- identifier: sourceData.identifier,
1900
- external_id: sourceData._id,
1901
- });
1902
- }
1903
- expect(activeEvent).toEqual({
1904
- title: sourceData.title,
1905
- identifier: sourceData.identifier,
1906
- external_id: sourceData._id,
1907
- });
1908
- });
1909
-
1910
- test("upserting a non-existent value", async () => {
1911
- // Schema
1912
- const Event = co.map({
1913
- title: z.string(),
1914
- identifier: z.string(),
1915
- external_id: z.string(),
1916
- });
1917
-
1918
- // Data
1919
- const sourceData = {
1920
- title: "Test Event Title",
1921
- identifier: "test-event-identifier",
1922
- _id: "test-event-external-id",
1923
- };
1924
- const workspace = Group.create();
1925
-
1926
- // Upserting
1927
- const activeEvent = await Event.upsertUnique({
1928
- value: {
1929
- title: sourceData.title,
1930
- identifier: sourceData.identifier,
1931
- external_id: sourceData._id,
1932
- },
1933
- unique: sourceData.identifier,
1934
- owner: workspace,
1935
- });
1936
- expect(activeEvent).toEqual({
1937
- title: sourceData.title,
1938
- identifier: sourceData.identifier,
1939
- external_id: sourceData._id,
1940
- });
1941
- });
1942
-
1943
- test("upserting without an active account", async () => {
1944
- const account = activeAccountContext.get();
1945
-
1946
- // Schema
1947
- const Event = co.map({
1948
- title: z.string(),
1949
- identifier: z.string(),
1950
- external_id: z.string(),
1951
- });
1952
-
1953
- // Data
1954
- const sourceData = {
1955
- title: "Test Event Title",
1956
- identifier: "test-event-identifier",
1957
- _id: "test-event-external-id",
1958
- };
1959
-
1960
- const activeEvent = await runWithoutActiveAccount(() => {
1961
- return Event.upsertUnique({
1962
- value: {
1963
- title: sourceData.title,
1964
- identifier: sourceData.identifier,
1965
- external_id: sourceData._id,
1966
- },
1967
- unique: sourceData.identifier,
1968
- owner: account,
1969
- });
1970
- });
1971
-
1972
- expect(activeEvent).toEqual({
1973
- title: sourceData.title,
1974
- identifier: sourceData.identifier,
1975
- external_id: sourceData._id,
1976
- });
1977
-
1978
- assert(activeEvent);
1979
-
1980
- expect(activeEvent.$jazz.owner).toEqual(account);
1981
- });
1982
-
1983
- test("upserting an existing value", async () => {
1984
- // Schema
1985
- const Event = co.map({
1986
- title: z.string(),
1987
- identifier: z.string(),
1988
- external_id: z.string(),
1989
- });
1990
-
1991
- // Data
1992
- const oldSourceData = {
1993
- title: "Old Event Title",
1994
- identifier: "test-event-identifier",
1995
- _id: "test-event-external-id",
1996
- };
1997
- const newSourceData = {
1998
- title: "New Event Title",
1999
- identifier: "test-event-identifier",
2000
- _id: "test-event-external-id",
2001
- };
2002
- expect(oldSourceData.identifier).toEqual(newSourceData.identifier);
2003
- const workspace = Group.create();
2004
- const oldActiveEvent = Event.create(
2005
- {
2006
- title: oldSourceData.title,
2007
- identifier: oldSourceData.identifier,
2008
- external_id: oldSourceData._id,
2009
- },
2010
- workspace,
2011
- );
2012
-
2013
- // Upserting
2014
- const activeEvent = await Event.upsertUnique({
2015
- value: {
2016
- title: newSourceData.title,
2017
- identifier: newSourceData.identifier,
2018
- external_id: newSourceData._id,
2019
- },
2020
- unique: newSourceData.identifier,
2021
- owner: workspace,
2022
- });
2023
- expect(activeEvent).toEqual({
2024
- title: newSourceData.title,
2025
- identifier: newSourceData.identifier,
2026
- external_id: newSourceData._id,
2027
- });
2028
- expect(activeEvent).not.toEqual(oldActiveEvent);
2029
- });
2030
-
2031
- test("upserting a non-existent value with resolve", async () => {
2032
- const Project = co.map({
2033
- name: z.string(),
2034
- });
2035
- const Organisation = co.map({
2036
- name: z.string(),
2037
- projects: co.list(Project),
2038
- });
2039
- const workspace = Group.create();
2040
-
2041
- const myOrg = await Organisation.upsertUnique({
2042
- value: {
2043
- name: "My organisation",
2044
- projects: co.list(Project).create(
2045
- [
2046
- Project.create(
2047
- {
2048
- name: "My project",
2049
- },
2050
- workspace,
2051
- ),
2052
- ],
2053
- workspace,
2054
- ),
2055
- },
2056
- unique: { name: "My organisation" },
2057
- owner: workspace,
2058
- resolve: {
2059
- projects: {
2060
- $each: true,
2061
- },
2062
- },
2063
- });
2064
- assert(myOrg);
2065
- expect(myOrg).not.toBeNull();
2066
- expect(myOrg.name).toEqual("My organisation");
2067
- expect(myOrg.projects.length).toBe(1);
2068
- expect(myOrg.projects[0]).toMatchObject({
2069
- name: "My project",
2070
- });
2071
- });
2072
-
2073
- test("upserting an existing value with resolve", async () => {
2074
- const Project = co.map({
2075
- name: z.string(),
2076
- });
2077
- const Organisation = co.map({
2078
- name: z.string(),
2079
- projects: co.list(Project),
2080
- });
2081
- const workspace = Group.create();
2082
- const initialProject = await Project.upsertUnique({
2083
- value: {
2084
- name: "My project",
2085
- },
2086
- unique: { unique: "First project" },
2087
- owner: workspace,
2088
- });
2089
- assert(initialProject);
2090
- expect(initialProject).not.toBeNull();
2091
- expect(initialProject.name).toEqual("My project");
2092
-
2093
- const myOrg = await Organisation.upsertUnique({
2094
- value: {
2095
- name: "My organisation",
2096
- projects: co.list(Project).create([initialProject], workspace),
2097
- },
2098
- unique: { name: "My organisation" },
2099
- owner: workspace,
2100
- resolve: {
2101
- projects: {
2102
- $each: true,
2103
- },
2104
- },
2105
- });
2106
- assert(myOrg);
2107
- expect(myOrg).not.toBeNull();
2108
- expect(myOrg.name).toEqual("My organisation");
2109
- expect(myOrg.projects.length).toBe(1);
2110
- expect(myOrg.projects.at(0)?.name).toEqual("My project");
2111
-
2112
- const updatedProject = await Project.upsertUnique({
2113
- value: {
2114
- name: "My updated project",
2115
- },
2116
- unique: { unique: "First project" },
2117
- owner: workspace,
2118
- });
2119
-
2120
- assert(updatedProject);
2121
- expect(updatedProject).not.toBeNull();
2122
- expect(updatedProject).toEqual(initialProject);
2123
- expect(updatedProject.name).toEqual("My updated project");
2124
- expect(myOrg.projects.length).toBe(1);
2125
- expect(myOrg.projects.at(0)?.name).toEqual("My updated project");
2126
- });
2127
-
2128
- test("upserting a partially loaded value on an new value with resolve", async () => {
2129
- const Project = co.map({
2130
- name: z.string(),
2131
- });
2132
- const Organisation = co.map({
2133
- name: z.string(),
2134
- projects: co.list(Project),
2135
- });
2136
- const publicAccess = Group.create();
2137
- publicAccess.addMember("everyone", "writer");
2138
-
2139
- const initialProject = await Project.upsertUnique({
2140
- value: {
2141
- name: "My project",
2142
- },
2143
- unique: { unique: "First project" },
2144
- owner: publicAccess,
2145
- });
2146
- assert(initialProject);
2147
- expect(initialProject).not.toBeNull();
2148
- expect(initialProject.name).toEqual("My project");
2149
-
2150
- const fullProjectList = co
2151
- .list(Project)
2152
- .create([initialProject], publicAccess);
2153
-
2154
- const account = await createJazzTestAccount({
2155
- isCurrentActiveAccount: true,
2156
- });
2157
-
2158
- const shallowProjectList = await co
2159
- .list(Project)
2160
- .load(fullProjectList.$jazz.id, {
2161
- loadAs: account,
2162
- });
2163
- assert(shallowProjectList);
2164
-
2165
- const publicAccessAsNewAccount = await Group.load(publicAccess.$jazz.id, {
2166
- loadAs: account,
2167
- });
2168
- assert(publicAccessAsNewAccount);
2169
-
2170
- const updatedOrg = await Organisation.upsertUnique({
2171
- value: {
2172
- name: "My organisation",
2173
- projects: shallowProjectList,
2174
- },
2175
- unique: { name: "My organisation" },
2176
- owner: publicAccessAsNewAccount,
2177
- resolve: {
2178
- projects: {
2179
- $each: true,
2180
- },
2181
- },
2182
- });
2183
-
2184
- assert(updatedOrg);
2185
-
2186
- expect(updatedOrg.projects.$jazz.id).toEqual(fullProjectList.$jazz.id);
2187
- expect(updatedOrg.projects.length).toBe(1);
2188
- expect(updatedOrg.projects.at(0)?.name).toEqual("My project");
2189
- });
2190
-
2191
- test("upserting a partially loaded value on an existing value with resolve", async () => {
2192
- const Project = co.map({
2193
- name: z.string(),
2194
- });
2195
- const Organisation = co.map({
2196
- name: z.string(),
2197
- projects: co.list(Project),
2198
- });
2199
- const publicAccess = Group.create();
2200
- publicAccess.addMember("everyone", "writer");
2201
-
2202
- const initialProject = await Project.upsertUnique({
2203
- value: {
2204
- name: "My project",
2205
- },
2206
- unique: { unique: "First project" },
2207
- owner: publicAccess,
2208
- });
2209
- assert(initialProject);
2210
- expect(initialProject).not.toBeNull();
2211
- expect(initialProject.name).toEqual("My project");
2212
-
2213
- const myOrg = await Organisation.upsertUnique({
2214
- value: {
2215
- name: "My organisation",
2216
- projects: co.list(Project).create([], publicAccess),
2217
- },
2218
- unique: { name: "My organisation" },
2219
- owner: publicAccess,
2220
- resolve: {
2221
- projects: {
2222
- $each: true,
2223
- },
2224
- },
2225
- });
2226
- assert(myOrg);
2227
-
2228
- const fullProjectList = co
2229
- .list(Project)
2230
- .create([initialProject], publicAccess);
2231
-
2232
- const account = await createJazzTestAccount({
2233
- isCurrentActiveAccount: true,
2234
- });
2235
-
2236
- const shallowProjectList = await co
2237
- .list(Project)
2238
- .load(fullProjectList.$jazz.id, {
2239
- loadAs: account,
2240
- });
2241
- assert(shallowProjectList);
2242
-
2243
- const publicAccessAsNewAccount = await Group.load(publicAccess.$jazz.id, {
2244
- loadAs: account,
2245
- });
2246
- assert(publicAccessAsNewAccount);
2247
-
2248
- const updatedOrg = await Organisation.upsertUnique({
2249
- value: {
2250
- name: "My organisation",
2251
- projects: shallowProjectList,
2252
- },
2253
- unique: { name: "My organisation" },
2254
- owner: publicAccessAsNewAccount,
2255
- resolve: {
2256
- projects: {
2257
- $each: true,
2258
- },
2259
- },
2260
- });
2261
-
2262
- assert(updatedOrg);
2263
-
2264
- expect(updatedOrg.projects.$jazz.id).toEqual(fullProjectList.$jazz.id);
2265
- expect(updatedOrg.projects.length).toBe(1);
2266
- expect(updatedOrg.projects.at(0)?.name).toEqual("My project");
2267
- expect(updatedOrg.$jazz.id).toEqual(myOrg.$jazz.id);
2268
- });
2269
1836
 
2270
1837
  test("complex discriminated union", () => {
2271
1838
  const StringTag = co.map({