@liminalfunctions/framework 1.0.43 → 1.0.44

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.
@@ -54,52 +54,65 @@ export class Collection_Brief_News_Category {
54
54
  let get_auth = this.get_auth;
55
55
  let collection_id = this.collection_id;
56
56
  let collection_name_plural = this.collection_name_plural;
57
- return {
58
- path: [...path, document_id],
59
- collection_id: collection_id,
60
- document_id: document_id,
61
- collection_name_plural: collection_name_plural,
62
- get_auth: get_auth,
63
- async get(): Promise<brief_news_category>{
64
- try {
65
- let result = await ky.get([...path, document_id].join('/'), {
66
- headers: {
67
- authorization: await get_auth()
68
- },
69
- }).json() as Response<brief_news_category>;
70
- return result.data;
71
- } catch(err){
72
- return Promise.reject(err)
73
- }
74
- },
57
+ return new Document(path, collection_id, document_id, collection_name_plural, get_auth);
58
+ }
59
+ }
60
+
61
+
75
62
 
76
- async put(update: brief_news_category_put): Promise<brief_news_category>{
77
- try {
78
- let result = await ky.put([...path, document_id].join('/'), {
79
- headers: {
80
- authorization: await get_auth()
81
- },
82
- json: update
83
- }).json() as Response<brief_news_category>;
84
- return result.data;
85
- } catch(err){
86
- return Promise.reject(err)
87
- }
88
- },
89
-
90
- async remove(): Promise<brief_news_category>{
91
- try {
92
- let result = await ky.delete([...path, document_id].join('/'), {
93
- headers: {
94
- authorization: await get_auth()
95
- },
96
- }).json() as Response<brief_news_category>;
97
- return result.data;
98
- } catch(err){
99
- return Promise.reject(err)
100
- }
101
- },
63
+ class Document {
64
+ path: string[];
65
+ collection_id: string;
66
+ document_id: string;
67
+ collection_name_plural: string;
68
+ get_auth: () => Promise<any>;
69
+
70
+ constructor(path: string[], collection_id: string, document_id: string, collection_name_plural: string, get_auth: () => Promise<any>) {
71
+ this.path = path;
72
+ this.collection_id = collection_id;
73
+ this.document_id = document_id;
74
+ this.collection_name_plural = collection_name_plural;
75
+ this.get_auth = get_auth;
76
+ }
102
77
 
78
+ async get(): Promise<brief_news_category>{
79
+ try {
80
+ let result = await ky.get([...this.path, this.document_id].join('/'), {
81
+ headers: {
82
+ authorization: await this.get_auth()
83
+ },
84
+ }).json() as Response<brief_news_category>;
85
+ return result.data;
86
+ } catch(err){
87
+ return Promise.reject(err)
88
+ }
89
+ }
90
+
91
+ async put(update: brief_news_category_put): Promise<brief_news_category>{
92
+ try {
93
+ let result = await ky.put([...this.path, this.document_id].join('/'), {
94
+ headers: {
95
+ authorization: await this.get_auth()
96
+ },
97
+ json: update
98
+ }).json() as Response<brief_news_category>;
99
+ return result.data;
100
+ } catch(err){
101
+ return Promise.reject(err)
103
102
  }
104
103
  }
104
+
105
+ async remove(): Promise<brief_news_category>{
106
+ try {
107
+ let result = await ky.delete([...this.path, this.document_id].join('/'), {
108
+ headers: {
109
+ authorization: await this.get_auth()
110
+ },
111
+ }).json() as Response<brief_news_category>;
112
+ return result.data;
113
+ } catch(err){
114
+ return Promise.reject(err)
115
+ }
116
+ }
117
+
105
118
  }
@@ -56,62 +56,77 @@ export class Collection_Client {
56
56
  let get_auth = this.get_auth;
57
57
  let collection_id = this.collection_id;
58
58
  let collection_name_plural = this.collection_name_plural;
59
- return {
60
- path: [...path, document_id],
61
- collection_id: collection_id,
62
- document_id: document_id,
63
- collection_name_plural: collection_name_plural,
64
- get_auth: get_auth,
65
- async get(): Promise<client>{
66
- try {
67
- let result = await ky.get([...path, document_id].join('/'), {
68
- headers: {
69
- authorization: await get_auth()
70
- },
71
- }).json() as Response<client>;
72
- return result.data;
73
- } catch(err){
74
- return Promise.reject(err)
75
- }
76
- },
59
+ return new Document(path, collection_id, document_id, collection_name_plural, get_auth);
60
+ }
61
+ }
62
+
63
+
64
+
65
+ class Document {
66
+ path: string[];
67
+ collection_id: string;
68
+ document_id: string;
69
+ collection_name_plural: string;
70
+ get_auth: () => Promise<any>;
71
+
72
+ constructor(path: string[], collection_id: string, document_id: string, collection_name_plural: string, get_auth: () => Promise<any>) {
73
+ this.path = path;
74
+ this.collection_id = collection_id;
75
+ this.document_id = document_id;
76
+ this.collection_name_plural = collection_name_plural;
77
+ this.get_auth = get_auth;
78
+ }
79
+
80
+ async get(): Promise<client>{
81
+ try {
82
+ let result = await ky.get([...this.path, this.document_id].join('/'), {
83
+ headers: {
84
+ authorization: await this.get_auth()
85
+ },
86
+ }).json() as Response<client>;
87
+ return result.data;
88
+ } catch(err){
89
+ return Promise.reject(err)
90
+ }
91
+ }
77
92
 
78
- async put(update: client_put): Promise<client>{
79
- try {
80
- let result = await ky.put([...path, document_id].join('/'), {
81
- headers: {
82
- authorization: await get_auth()
83
- },
84
- json: update
85
- }).json() as Response<client>;
86
- return result.data;
87
- } catch(err){
88
- return Promise.reject(err)
89
- }
90
- },
91
-
92
- async remove(): Promise<client>{
93
- try {
94
- let result = await ky.delete([...path, document_id].join('/'), {
95
- headers: {
96
- authorization: await get_auth()
97
- },
98
- }).json() as Response<client>;
99
- return result.data;
100
- } catch(err){
101
- return Promise.reject(err)
102
- }
103
- },
93
+ async put(update: client_put): Promise<client>{
94
+ try {
95
+ let result = await ky.put([...this.path, this.document_id].join('/'), {
96
+ headers: {
97
+ authorization: await this.get_auth()
98
+ },
99
+ json: update
100
+ }).json() as Response<client>;
101
+ return result.data;
102
+ } catch(err){
103
+ return Promise.reject(err)
104
+ }
105
+ }
106
+
107
+ async remove(): Promise<client>{
108
+ try {
109
+ let result = await ky.delete([...this.path, this.document_id].join('/'), {
110
+ headers: {
111
+ authorization: await this.get_auth()
112
+ },
113
+ }).json() as Response<client>;
114
+ return result.data;
115
+ } catch(err){
116
+ return Promise.reject(err)
117
+ }
118
+ }
104
119
 
105
- collection(collection_id: "project" | "brief_news_category") {
106
- switch(collection_id) {
107
- case "project":
108
- return new Collection_Project([...path, document_id, "project"], get_auth);
109
- case "brief_news_category":
110
- return new Collection_Brief_News_Category([...path, document_id, "brief_news_category"], get_auth);
111
- default:
112
- throw new Error(`Api does not have the collection ${collection_id}`)
113
- }
114
- }
120
+ collection(collection_id: "project"): Collection_Project;
121
+ collection(collection_id: "brief_news_category"): Collection_Brief_News_Category;
122
+ collection(collection_id: string) {
123
+ switch(collection_id) {
124
+ case "project":
125
+ return new Collection_Project([...this.path, this.document_id, "project"], this.get_auth);
126
+ case "brief_news_category":
127
+ return new Collection_Brief_News_Category([...this.path, this.document_id, "brief_news_category"], this.get_auth);
128
+ default:
129
+ throw new Error(`Api does not have the collection ${collection_id}`)
115
130
  }
116
131
  }
117
132
  }
@@ -55,60 +55,74 @@ export class Collection_Institution {
55
55
  let get_auth = this.get_auth;
56
56
  let collection_id = this.collection_id;
57
57
  let collection_name_plural = this.collection_name_plural;
58
- return {
59
- path: [...path, document_id],
60
- collection_id: collection_id,
61
- document_id: document_id,
62
- collection_name_plural: collection_name_plural,
63
- get_auth: get_auth,
64
- async get(): Promise<institution>{
65
- try {
66
- let result = await ky.get([...path, document_id].join('/'), {
67
- headers: {
68
- authorization: await get_auth()
69
- },
70
- }).json() as Response<institution>;
71
- return result.data;
72
- } catch(err){
73
- return Promise.reject(err)
74
- }
75
- },
58
+ return new Document(path, collection_id, document_id, collection_name_plural, get_auth);
59
+ }
60
+ }
61
+
62
+
63
+
64
+ class Document {
65
+ path: string[];
66
+ collection_id: string;
67
+ document_id: string;
68
+ collection_name_plural: string;
69
+ get_auth: () => Promise<any>;
70
+
71
+ constructor(path: string[], collection_id: string, document_id: string, collection_name_plural: string, get_auth: () => Promise<any>) {
72
+ this.path = path;
73
+ this.collection_id = collection_id;
74
+ this.document_id = document_id;
75
+ this.collection_name_plural = collection_name_plural;
76
+ this.get_auth = get_auth;
77
+ }
78
+
79
+ async get(): Promise<institution>{
80
+ try {
81
+ let result = await ky.get([...this.path, this.document_id].join('/'), {
82
+ headers: {
83
+ authorization: await this.get_auth()
84
+ },
85
+ }).json() as Response<institution>;
86
+ return result.data;
87
+ } catch(err){
88
+ return Promise.reject(err)
89
+ }
90
+ }
76
91
 
77
- async put(update: institution_put): Promise<institution>{
78
- try {
79
- let result = await ky.put([...path, document_id].join('/'), {
80
- headers: {
81
- authorization: await get_auth()
82
- },
83
- json: update
84
- }).json() as Response<institution>;
85
- return result.data;
86
- } catch(err){
87
- return Promise.reject(err)
88
- }
89
- },
90
-
91
- async remove(): Promise<institution>{
92
- try {
93
- let result = await ky.delete([...path, document_id].join('/'), {
94
- headers: {
95
- authorization: await get_auth()
96
- },
97
- }).json() as Response<institution>;
98
- return result.data;
99
- } catch(err){
100
- return Promise.reject(err)
101
- }
102
- },
92
+ async put(update: institution_put): Promise<institution>{
93
+ try {
94
+ let result = await ky.put([...this.path, this.document_id].join('/'), {
95
+ headers: {
96
+ authorization: await this.get_auth()
97
+ },
98
+ json: update
99
+ }).json() as Response<institution>;
100
+ return result.data;
101
+ } catch(err){
102
+ return Promise.reject(err)
103
+ }
104
+ }
105
+
106
+ async remove(): Promise<institution>{
107
+ try {
108
+ let result = await ky.delete([...this.path, this.document_id].join('/'), {
109
+ headers: {
110
+ authorization: await this.get_auth()
111
+ },
112
+ }).json() as Response<institution>;
113
+ return result.data;
114
+ } catch(err){
115
+ return Promise.reject(err)
116
+ }
117
+ }
103
118
 
104
- collection(collection_id: "client") {
105
- switch(collection_id) {
106
- case "client":
107
- return new Collection_Client([...path, document_id, "client"], get_auth);
108
- default:
109
- throw new Error(`Api does not have the collection ${collection_id}`)
110
- }
111
- }
119
+ collection(collection_id: "client"): Collection_Client;
120
+ collection(collection_id: string) {
121
+ switch(collection_id) {
122
+ case "client":
123
+ return new Collection_Client([...this.path, this.document_id, "client"], this.get_auth);
124
+ default:
125
+ throw new Error(`Api does not have the collection ${collection_id}`)
112
126
  }
113
127
  }
114
128
  }
@@ -54,52 +54,65 @@ export class Collection_Project {
54
54
  let get_auth = this.get_auth;
55
55
  let collection_id = this.collection_id;
56
56
  let collection_name_plural = this.collection_name_plural;
57
- return {
58
- path: [...path, document_id],
59
- collection_id: collection_id,
60
- document_id: document_id,
61
- collection_name_plural: collection_name_plural,
62
- get_auth: get_auth,
63
- async get(): Promise<project>{
64
- try {
65
- let result = await ky.get([...path, document_id].join('/'), {
66
- headers: {
67
- authorization: await get_auth()
68
- },
69
- }).json() as Response<project>;
70
- return result.data;
71
- } catch(err){
72
- return Promise.reject(err)
73
- }
74
- },
57
+ return new Document(path, collection_id, document_id, collection_name_plural, get_auth);
58
+ }
59
+ }
60
+
61
+
75
62
 
76
- async put(update: project_put): Promise<project>{
77
- try {
78
- let result = await ky.put([...path, document_id].join('/'), {
79
- headers: {
80
- authorization: await get_auth()
81
- },
82
- json: update
83
- }).json() as Response<project>;
84
- return result.data;
85
- } catch(err){
86
- return Promise.reject(err)
87
- }
88
- },
89
-
90
- async remove(): Promise<project>{
91
- try {
92
- let result = await ky.delete([...path, document_id].join('/'), {
93
- headers: {
94
- authorization: await get_auth()
95
- },
96
- }).json() as Response<project>;
97
- return result.data;
98
- } catch(err){
99
- return Promise.reject(err)
100
- }
101
- },
63
+ class Document {
64
+ path: string[];
65
+ collection_id: string;
66
+ document_id: string;
67
+ collection_name_plural: string;
68
+ get_auth: () => Promise<any>;
69
+
70
+ constructor(path: string[], collection_id: string, document_id: string, collection_name_plural: string, get_auth: () => Promise<any>) {
71
+ this.path = path;
72
+ this.collection_id = collection_id;
73
+ this.document_id = document_id;
74
+ this.collection_name_plural = collection_name_plural;
75
+ this.get_auth = get_auth;
76
+ }
102
77
 
78
+ async get(): Promise<project>{
79
+ try {
80
+ let result = await ky.get([...this.path, this.document_id].join('/'), {
81
+ headers: {
82
+ authorization: await this.get_auth()
83
+ },
84
+ }).json() as Response<project>;
85
+ return result.data;
86
+ } catch(err){
87
+ return Promise.reject(err)
88
+ }
89
+ }
90
+
91
+ async put(update: project_put): Promise<project>{
92
+ try {
93
+ let result = await ky.put([...this.path, this.document_id].join('/'), {
94
+ headers: {
95
+ authorization: await this.get_auth()
96
+ },
97
+ json: update
98
+ }).json() as Response<project>;
99
+ return result.data;
100
+ } catch(err){
101
+ return Promise.reject(err)
103
102
  }
104
103
  }
104
+
105
+ async remove(): Promise<project>{
106
+ try {
107
+ let result = await ky.delete([...this.path, this.document_id].join('/'), {
108
+ headers: {
109
+ authorization: await this.get_auth()
110
+ },
111
+ }).json() as Response<project>;
112
+ return result.data;
113
+ } catch(err){
114
+ return Promise.reject(err)
115
+ }
116
+ }
117
+
105
118
  }
@@ -5,16 +5,25 @@ import { Collection_Institution } from "./Institution.js"
5
5
 
6
6
 
7
7
  export function api(base_url: string, get_auth: () => Promise<any>) {
8
- return {
9
- collection(collection_id: "institution") {
10
- switch(collection_id) {
11
- case "institution":
12
- return new Collection_Institution([base_url, "institution"], get_auth);
13
- default:
14
- throw new Error(`Api does not have the collection ${collection_id}`)
15
- }
16
- }
17
- }
8
+ return new Api(base_url, get_auth)
18
9
  }
19
10
 
11
+ class Api {
12
+ base_url: string;
13
+ get_auth: () => Promise<any>
14
+
15
+ constructor(base_url: string, get_auth: () => Promise<any>) {
16
+ this.base_url = base_url;
17
+ this.get_auth = get_auth
18
+ }
20
19
 
20
+ collection(collection_id: "institution"): Collection_Institution;
21
+ collection(collection_id: string) {
22
+ switch(collection_id) {
23
+ case "institution":
24
+ return new Collection_Institution([this.base_url, "institution"], this.get_auth);
25
+ default:
26
+ throw new Error(`Api does not have the collection ${collection_id}`)
27
+ }
28
+ }
29
+ }