@naanlang/naan 1.0.12 → 1.0.14

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.
@@ -1,161 +0,0 @@
1
- /*
2
- * yc_function.nlg
3
- * serviceYC
4
- *
5
- * Access to serverless function management services for YC.
6
- *
7
- * column positioning: // // !
8
- *
9
- * Copyright (c) 2022 by Richard C. Zulch
10
- *
11
- */
12
-
13
-
14
- /*
15
- * YCFunction
16
- *
17
- * YCFunction manipulation functions.
18
- *
19
- */
20
-
21
- closure YCFunction(local ycfun) {
22
- ycfun = new(object, this)
23
-
24
- //
25
- // login
26
- //
27
- ycfun.login = closure login(creds) {
28
- ycfun.creds = creds
29
- list(false, { ok: true })
30
- }
31
-
32
- //
33
- // getFunction
34
- //
35
- // Get basic function info like:
36
- // {
37
- // id : "d4er5sq67r5j47nno6nb",
38
- // folderId : "b1gjjahqm5u9tjolom9l",
39
- // createdAt : "2022-08-30T00:57:18.024Z",
40
- // name : "hello-world",
41
- // description : "A quick first function.",
42
- // logGroupId : "ckgbmh6df6dt92pphc6b",
43
- // httpInvokeUrl: "https://functions.yandexcloud.net/d4er5sq67r5j47nno6nb",
44
- // status : "ACTIVE"
45
- // }
46
- //
47
- ycfun.getFunction = closure getFunction(funcID, local url, error, data) {
48
- debuglog("YCFunction.getFunction", funcID)
49
- url = "https://serverless-functions.api.cloud.yandex.net/functions/v1/functions/".concat(funcID)
50
- `(error, data) = YcRequest(url, ycfun.creds, {
51
- query: { x: 1 }
52
- })
53
- if error
54
- debuglog("YCFunction.getFunction failed:", ErrorString(error))
55
- list(error, data)
56
- }
57
-
58
- //
59
- // getVersionByTag
60
- //
61
- // Get info about a specific function version using its tag, e.g. $latest:
62
- // {
63
- // resources : { memory: "134217728" },
64
- // tags : ["$latest"],
65
- // id : "d4evm4lsi91hqkv78ane",
66
- // functionId : "d4er5sq67r5j47nno6nb",
67
- // createdAt : "2022-08-31T03:32:59.577Z",
68
- // runtime : "nodejs16",
69
- // entrypoint : "index.handler",
70
- // executionTimeout: "3s",
71
- // serviceAccountId: "aje9s3df60gofsddio0c",
72
- // imageSize : "4096",
73
- // status : "ACTIVE",
74
- // logGroupId : "ckgbmh6df6dt92pphc6b" }
75
- // }
76
- //
77
- ycfun.getVersionByTag = closure getVersionByTag(funcID, tag, local url, error, data) {
78
- url = "https://serverless-functions.api.cloud.yandex.net/functions/v1/versions:byTag".concat(
79
- EncodeQuery("?", {
80
- functionId: funcID
81
- tag: tag
82
- }))
83
- `(error, data) = YcRequest(url, ycfun.creds, {
84
- query: { x: 1 }
85
- })
86
- if error
87
- debuglog("YCFunction.getVersionByTag failed:", ErrorString(error))
88
- list(error, data)
89
- }
90
-
91
- //
92
- // invokeFunction
93
- //
94
- // Invoke a public cloud function. It is impossible to invoke a private cloud function from
95
- // browsers because the function cannot respond to a CORS authorization request using the OPTIONS
96
- // method without an authorization header that cannot be added to the preflight.
97
- //
98
- ycfun.invokeFunction = closure invokeFunction(funcID, local url, error, data) {
99
- url = "https://functions.yandexcloud.net/".concat(funcID)
100
- `(error, data) = https.HttpsApiRequest(url, {
101
- query: { x: 1 }
102
- })
103
- if error
104
- debuglog("YCFunction.invokeFunction failed:", ErrorString(error))
105
- list(error, data)
106
- }
107
-
108
- //
109
- // updateFunctionCode
110
- //
111
- //
112
- ycfun.updateFunctionCode = closure updateFunctionCode(info, bucket, key, sha256,
113
- local url, params, error, data) {
114
- params = {
115
- function_id: info.functionId
116
- functionID: info.functionId
117
- runtime: info.runtime
118
- description: "Updated: ".concat(Date())
119
- entrypoint: info.entrypoint
120
- resources: info.resources
121
- executionTimeout: info.executionTimeout
122
- serviceAccountId: info.serviceAccountId
123
- package: {
124
- bucketName: bucket
125
- objectName: key
126
- sha256: sha256
127
- }
128
- }
129
- if info.environment
130
- params.environment = info.environment
131
- url = "https://serverless-functions.api.cloud.yandex.net/functions/v1/versions"
132
- `(error, data) = YcRequest(url, ycfun.creds, {
133
- putdata: params
134
- })
135
- if error
136
- debuglog("YCFunction.updateFunctionCode failed:", ErrorString(error))
137
- list(error, data)
138
- }
139
-
140
- // finis
141
- ycfun
142
- }
143
-
144
-
145
- /*
146
- * ycFunctionInit
147
- *
148
- * Initialize the module.
149
- *
150
- */
151
-
152
- function ycFunctionInit(local manifest) {
153
- manifest = `(YCFunction, ycFunctionInit)
154
-
155
- Naan.module.build(module.id, "yc_function", function(modobj, compobj) {
156
- require("./serviceYC.nlg")
157
- compobj.manifest = manifest
158
- modobj.exports.YCFunction = YCFunction
159
- })
160
-
161
- } ();