From 88b4fbba444dd0374ab9e9e6ccf57d012a9ae2aa Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Fri, 7 Jul 2023 12:33:20 +1000 Subject: [PATCH] remove old example code. --- examples/documents/delete.ts | 26 ------- examples/documents/document-examples.test.ts | 73 -------------------- examples/documents/get.ts | 25 ------- examples/documents/query-filter.ts | 30 -------- examples/documents/query-limits.ts | 26 ------- examples/documents/query-paginated.ts | 36 ---------- examples/documents/query-stream.ts | 28 -------- examples/documents/query.ts | 27 -------- examples/documents/refs.ts | 26 ------- examples/documents/set.ts | 36 ---------- examples/documents/sub-col-query.ts | 29 -------- examples/documents/sub-doc-query.ts | 30 -------- examples/events/events-examples.test.ts | 35 ---------- examples/events/publish-ids.ts | 33 --------- examples/events/publish.ts | 33 --------- examples/faas/events.ts | 33 --------- examples/faas/faas-examples.test.ts | 62 ----------------- examples/queues/failed.ts | 31 --------- examples/queues/queues-examples.test.ts | 42 ----------- examples/queues/receive.ts | 32 --------- examples/queues/send.ts | 27 -------- examples/queues/send_id.ts | 27 -------- examples/secrets/access.ts | 25 ------- examples/secrets/latest.ts | 22 ------ examples/secrets/put.ts | 25 ------- examples/secrets/secrets-examples.test.ts | 68 ------------------ examples/storage/delete.ts | 26 ------- examples/storage/read.ts | 26 ------- examples/storage/signed-url-read.ts | 34 --------- examples/storage/signed-url-write.ts | 42 ----------- examples/storage/storage-examples.test.ts | 55 --------------- examples/storage/write.ts | 29 -------- 32 files changed, 1099 deletions(-) delete mode 100644 examples/documents/delete.ts delete mode 100644 examples/documents/document-examples.test.ts delete mode 100644 examples/documents/get.ts delete mode 100644 examples/documents/query-filter.ts delete mode 100644 examples/documents/query-limits.ts delete mode 100644 examples/documents/query-paginated.ts delete mode 100644 examples/documents/query-stream.ts delete mode 100644 examples/documents/query.ts delete mode 100644 examples/documents/refs.ts delete mode 100644 examples/documents/set.ts delete mode 100644 examples/documents/sub-col-query.ts delete mode 100644 examples/documents/sub-doc-query.ts delete mode 100644 examples/events/events-examples.test.ts delete mode 100644 examples/events/publish-ids.ts delete mode 100644 examples/events/publish.ts delete mode 100644 examples/faas/events.ts delete mode 100644 examples/faas/faas-examples.test.ts delete mode 100644 examples/queues/failed.ts delete mode 100644 examples/queues/queues-examples.test.ts delete mode 100644 examples/queues/receive.ts delete mode 100644 examples/queues/send.ts delete mode 100644 examples/queues/send_id.ts delete mode 100644 examples/secrets/access.ts delete mode 100644 examples/secrets/latest.ts delete mode 100644 examples/secrets/put.ts delete mode 100644 examples/secrets/secrets-examples.test.ts delete mode 100644 examples/storage/delete.ts delete mode 100644 examples/storage/read.ts delete mode 100644 examples/storage/signed-url-read.ts delete mode 100644 examples/storage/signed-url-write.ts delete mode 100644 examples/storage/storage-examples.test.ts delete mode 100644 examples/storage/write.ts diff --git a/examples/documents/delete.ts b/examples/documents/delete.ts deleted file mode 100644 index 714e27b5..00000000 --- a/examples/documents/delete.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { documents } from '@nitric/sdk'; -// [END import] - -export async function deleteDocument() { - // [START snippet] - const docs = documents(); - - const document = docs.collection('products').doc('nitric'); - - await document.delete(); - // [END snippet] -} diff --git a/examples/documents/document-examples.test.ts b/examples/documents/document-examples.test.ts deleted file mode 100644 index 03a5e6f7..00000000 --- a/examples/documents/document-examples.test.ts +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -import { - DocumentServiceClient -} from '@nitric/api/proto/document/v1/document_grpc_pb'; -import { - DocumentQueryResponse, - DocumentGetResponse, - DocumentSetResponse, - DocumentDeleteResponse, -} from '@nitric/api/proto/document/v1/document_pb'; -import { PassThrough } from 'stream'; -import { deleteDocument } from './delete'; -import { getDocument } from './get'; -import { queryDocument } from './query'; -import { queryFilterDocument } from './query-filter'; -import { queryLimitsDocument } from './query-limits'; -import { queryPaginatedDocument } from './query-paginated'; -import { queryStreamDocument } from './query-stream'; -import { getDocumentRef } from './refs'; -import { setDocument } from './set'; -import { querySubColQuery } from './sub-col-query'; -import { querySubDocQuery } from './sub-doc-query'; - -const docProto = DocumentServiceClient.prototype; - -const CALLBACKFN = (response) => (_, cb: any) => cb(null, response); - -describe('test document snippets', () => { - beforeAll(() => { - jest - .spyOn(docProto, 'get') - .mockImplementation(CALLBACKFN(new DocumentGetResponse())); - jest - .spyOn(docProto, 'set') - .mockImplementation(CALLBACKFN(new DocumentSetResponse())); - jest - .spyOn(docProto, 'delete') - .mockImplementation(CALLBACKFN(new DocumentDeleteResponse())); - jest - .spyOn(docProto, 'query') - .mockImplementation(CALLBACKFN(new DocumentQueryResponse())); - jest - .spyOn(docProto, 'queryStream') - // @ts-ignore - .mockReturnValueOnce(new PassThrough().end()); - }); - - test('ensure all document snippets run', async () => { - expect(getDocumentRef()).toEqual(undefined); - await expect(getDocument()).resolves.toEqual(null); - await expect(setDocument()).resolves.toEqual(undefined); - await expect(deleteDocument()).resolves.toEqual(undefined); - await expect(queryDocument()).resolves.toEqual(undefined); - await expect(queryFilterDocument()).resolves.toEqual(undefined); - await expect(queryLimitsDocument()).resolves.toEqual(undefined); - await expect(queryPaginatedDocument()).resolves.toEqual(undefined); - await expect(queryStreamDocument()).resolves.toEqual(undefined); - await expect(querySubDocQuery()).resolves.toEqual(undefined); - await expect(querySubColQuery()).resolves.toEqual(undefined); - }); -}); diff --git a/examples/documents/get.ts b/examples/documents/get.ts deleted file mode 100644 index d7b9f34b..00000000 --- a/examples/documents/get.ts +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { documents } from '@nitric/sdk'; -// [END import] - -export async function getDocument() { - // [START snippet] - const documentRef = documents().collection('products').doc('nitric'); - - const product = await documentRef.get(); - // [END snippet] - return product; -} diff --git a/examples/documents/query-filter.ts b/examples/documents/query-filter.ts deleted file mode 100644 index caf2c04a..00000000 --- a/examples/documents/query-filter.ts +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { documents } from '@nitric/sdk'; -// [END import] - -export async function queryFilterDocument() { - // [START snippet] - const docs = documents(); - - const query = docs - .collection('Customers') - .query() - .where('country', '==', 'US') - .where('age', '>=', 21); - - const results = await query.fetch(); - // [END snippet] -} diff --git a/examples/documents/query-limits.ts b/examples/documents/query-limits.ts deleted file mode 100644 index c240241e..00000000 --- a/examples/documents/query-limits.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { documents } from '@nitric/sdk'; -// [END import] - -export async function queryLimitsDocument() { - // [START snippet] - const docs = documents(); - - const query = docs.collection('Customers').query().limit(1000); - - const results = await query.fetch(); - // [END snippet] -} diff --git a/examples/documents/query-paginated.ts b/examples/documents/query-paginated.ts deleted file mode 100644 index 5820c5b8..00000000 --- a/examples/documents/query-paginated.ts +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { documents } from '@nitric/sdk'; -// [END import] - -export async function queryPaginatedDocument() { - // [START snippet] - const docs = documents(); - - const query = docs - .collection('Customers') - .query() - .where('active', '==', true) - .limit(100); - - // Fetch first page - let results = await query.fetch(); - - // Fetch next page - if (results.pagingToken) { - results = await query.pagingFrom(results.pagingToken).fetch(); - } - // [END snippet] -} diff --git a/examples/documents/query-stream.ts b/examples/documents/query-stream.ts deleted file mode 100644 index 391c8820..00000000 --- a/examples/documents/query-stream.ts +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { documents } from '@nitric/sdk'; -// [END import] - -export async function queryStreamDocument() { - // [START snippet] - const docs = documents(); - - const stream = docs.collection('Customers').query().stream(); - - for await (const doc of stream) { - // Process doc stream... - } - // [END snippet] -} diff --git a/examples/documents/query.ts b/examples/documents/query.ts deleted file mode 100644 index 53dbc353..00000000 --- a/examples/documents/query.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { documents } from '@nitric/sdk'; -// [END import] - -export async function queryDocument() { - // [START snippet] - const docs = documents(); - - const query = docs.collection('Customers').query(); - - // Execute query - const results = await query.fetch(); - // [END snippet] -} diff --git a/examples/documents/refs.ts b/examples/documents/refs.ts deleted file mode 100644 index 936f115f..00000000 --- a/examples/documents/refs.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { documents } from '@nitric/sdk'; -// [END import] - -export function getDocumentRef() { - // [START snippet] - // Create a reference to a collection named 'products' - const products = documents().collection('products'); - - // Create a reference to a document with the id 'nitric' - const nitric = products.doc('nitric'); - // [END snippet] -} diff --git a/examples/documents/set.ts b/examples/documents/set.ts deleted file mode 100644 index fe57ed20..00000000 --- a/examples/documents/set.ts +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { documents } from '@nitric/sdk'; -// [END import] - -export async function setDocument() { - // [START snippet] - interface Product { - id: string; - name: string; - description: string; - } - - const docs = documents(); - - const document = docs.collection('products').doc('nitric'); - - await document.set({ - id: 'nitric', - name: 'nitric', - description: 'A development framework!', - }); - // [END snippet] -} diff --git a/examples/documents/sub-col-query.ts b/examples/documents/sub-col-query.ts deleted file mode 100644 index 6eb9171d..00000000 --- a/examples/documents/sub-col-query.ts +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { documents } from '@nitric/sdk'; -// [END import] - -export async function querySubColQuery() { - // [START snippet] - const docs = documents(); - - const query = docs - .collection('Customers') - .collection('Order') - .query(); - - const results = await query.fetch(); - // [END snippet] -} diff --git a/examples/documents/sub-doc-query.ts b/examples/documents/sub-doc-query.ts deleted file mode 100644 index f529f090..00000000 --- a/examples/documents/sub-doc-query.ts +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { documents } from '@nitric/sdk'; -// [END import] - -export async function querySubDocQuery() { - // [START snippet] - const docs = documents(); - - const query = docs - .collection('Customers') - .doc('apple') - .collection('Orders') - .query(); - - const results = await query.fetch(); - // [END snippet] -} diff --git a/examples/events/events-examples.test.ts b/examples/events/events-examples.test.ts deleted file mode 100644 index 0af7caab..00000000 --- a/examples/events/events-examples.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -import { EventServiceClient } from '@nitric/api/proto/event/v1/event_grpc_pb'; -import { EventPublishResponse } from '@nitric/api/proto/event/v1/event_pb'; - -import { eventsPublish } from './publish'; -import { eventsPublishIds } from './publish-ids'; - -const proto = EventServiceClient.prototype; - -const CALLBACKFN = (response) => (_, cb: any) => cb(null, response); - -describe('test events snippets', () => { - beforeAll(() => { - jest - .spyOn(proto, 'publish') - .mockImplementation(CALLBACKFN(new EventPublishResponse())); - }); - - test('ensure all events snippets run', async () => { - await expect(eventsPublish()).resolves.toEqual(undefined); - await expect(eventsPublishIds()).resolves.toEqual(undefined); - }); -}); diff --git a/examples/events/publish-ids.ts b/examples/events/publish-ids.ts deleted file mode 100644 index 25e0c3c6..00000000 --- a/examples/events/publish-ids.ts +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { events } from '@nitric/sdk'; -// [END import] - -export async function eventsPublishIds() { - // [START snippet] - const topic = events().topic('my-topic'); - - const event = { - // Note: the event id should be generated using a process - // that's guaranteed to be unique for practical purposes. - id: 'unique-event-id', - payload: { - value: 'Hello World!', - }, - }; - - await topic.publish(event); - // [END snippet] -} diff --git a/examples/events/publish.ts b/examples/events/publish.ts deleted file mode 100644 index fe9e9b07..00000000 --- a/examples/events/publish.ts +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { events } from '@nitric/sdk'; -// [END import] - -export async function eventsPublish() { - // [START snippet] - const topic = events().topic('my-topic'); - - const event = { - payloadType: 'my-payload', - payload: { - value: 'Hello World!', - }, - }; - - // Publish an event to the topic 'my-topic' - // Note: The event payload will be serialized automatically. - await topic.publish(event); - // [END snippet] -} diff --git a/examples/faas/events.ts b/examples/faas/events.ts deleted file mode 100644 index 5ac37138..00000000 --- a/examples/faas/events.ts +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// [START import] -import { faas } from "@nitric/sdk"; -// [END import] - -export const events = async () => { - // [START snippet] - await faas - .event(async (ctx) => { - console.log("received event: ", ctx.req.json()); - - // mark the event as successfully handled - ctx.res.success = true; - - return ctx; - }) - .start(); - // [END snippet] -} - diff --git a/examples/faas/faas-examples.test.ts b/examples/faas/faas-examples.test.ts deleted file mode 100644 index 8e25c810..00000000 --- a/examples/faas/faas-examples.test.ts +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -import { events } from './events'; -import { FaasServiceClient } from '@nitric/api/proto/faas/v1/faas_grpc_pb'; - -const proto = FaasServiceClient.prototype; - -// We only need to handle half of the duplex stream -class MockClientStream { - public recievedMessages: Req[] = []; - - private listeners: { - [event: string]: ((req: Resp | string) => void)[]; - } = {}; - - public write(req: Req) { - this.recievedMessages.push(req); - } - - public on(event: string, cback: (req: Resp) => void) { - if (!this.listeners[event]) { - this.listeners[event] = []; - } - this.listeners[event].push(cback); - } - - public emit(event: string, req: Resp | string) { - if (this.listeners[event]) { - this.listeners[event].forEach((l) => l(req)); - } - } -} - -describe('test queues snippets', () => { - let mockStream = null as any; - - beforeEach(() => { - mockStream = new MockClientStream() as any; - jest.spyOn(proto, 'triggerStream').mockReturnValue(mockStream); - }); - - test('events snippet', async () => { - // Ensure event snippet is valid typescript - const evtPromise = events(); - - // close the stream - mockStream.emit('end', 'EOF'); - - await expect(evtPromise).resolves.toEqual(undefined); - }); -}); diff --git a/examples/queues/failed.ts b/examples/queues/failed.ts deleted file mode 100644 index 2362379f..00000000 --- a/examples/queues/failed.ts +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { queues } from '@nitric/sdk'; -// [END import] - -export async function queueFailed(): Promise { - // [START snippet] - const taskList = [{ id: '1' }, { id: '2' }] - // Publish a collection of tasks - const failedMessages = await queues() - .queue('my-queue') - .send(taskList) - - // Check that it returned Failed Messages - for (const message in failedMessages) { - console.log(message) - } - // [END snippet] -} diff --git a/examples/queues/queues-examples.test.ts b/examples/queues/queues-examples.test.ts deleted file mode 100644 index 3f494006..00000000 --- a/examples/queues/queues-examples.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -import { queueReceive } from './receive'; -import { queueSend } from './send'; -import { QueueServiceClient } from '@nitric/api/proto/queue/v1/queue_grpc_pb'; -import { - QueueReceiveResponse, - QueueSendBatchResponse, -} from '@nitric/api/proto/queue/v1/queue_pb'; -import { queueFailed } from './failed'; - -const proto = QueueServiceClient.prototype; - -const CALLBACKFN = (response) => (_, cb: any) => cb(null, response); - -describe('test queues snippets', () => { - beforeAll(() => { - jest - .spyOn(proto, 'sendBatch') - .mockImplementation(CALLBACKFN(new QueueSendBatchResponse())); - jest - .spyOn(proto, 'receive') - .mockImplementation(CALLBACKFN(new QueueReceiveResponse())); - }); - - test('ensure all queues snippets run', async () => { - await expect(queueSend()).resolves.toEqual(undefined); - await expect(queueReceive()).resolves.toEqual(undefined); - await expect(queueFailed()).resolves.toEqual(undefined); - }); -}); diff --git a/examples/queues/receive.ts b/examples/queues/receive.ts deleted file mode 100644 index 2de4c2f0..00000000 --- a/examples/queues/receive.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { queues } from '@nitric/sdk'; -// [END import] - -export async function queueReceive() { - // [START snippet] - // Receive tasks from the queue - const tasks = await queues().queue('my-queue').receive(); - - await Promise.all( - tasks.map((task) => { - // Work on a task... - - // Complete the task - return task.complete(); - }) - ); - // [END snippet] -} diff --git a/examples/queues/send.ts b/examples/queues/send.ts deleted file mode 100644 index cfeb5779..00000000 --- a/examples/queues/send.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { queues } from '@nitric/sdk'; -// [END import] - -export async function queueSend(): Promise { - // [START snippet] - // Publish a task to the queue - const payload = { - example: 'payload', - }; - - await queues().queue('my-queue').send({ payload }); - // [END snippet] -} diff --git a/examples/queues/send_id.ts b/examples/queues/send_id.ts deleted file mode 100644 index 5e0ca78d..00000000 --- a/examples/queues/send_id.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { queues } from '@nitric/sdk'; -// [END import] - -export async function queueSend(): Promise { - // [START snippet] - // Publish a task to the queue - const payload = { - example: 'payload', - }; - - await queues().queue('my-queue').send({ id: 'unique-task-id', payload: payload }); - // [END snippet] -} diff --git a/examples/secrets/access.ts b/examples/secrets/access.ts deleted file mode 100644 index 55cf6e98..00000000 --- a/examples/secrets/access.ts +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { secrets } from '@nitric/sdk'; -// [END import] - -export async function secretsAccess() { - // [START snippet] - // Access the latest secret - const value = await secrets().secret('database.password').latest().access(); - - const password = value.asString(); - // [END snippet] -} diff --git a/examples/secrets/latest.ts b/examples/secrets/latest.ts deleted file mode 100644 index 5635c7ac..00000000 --- a/examples/secrets/latest.ts +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { secrets } from '@nitric/sdk'; -// [END import] - -export async function secretsLatest() { - // [START snippet] - const latestVersion = secrets().secret('database.password').latest(); - // [END snippet] -} diff --git a/examples/secrets/put.ts b/examples/secrets/put.ts deleted file mode 100644 index 8d8716ce..00000000 --- a/examples/secrets/put.ts +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { secrets } from '@nitric/sdk'; -// [END import] - -export async function secretsPut() { - // [START snippet] - const newPassword = 'qxGJp9rWMbYvPEsNFXzukQa!'; - - // Store the new password value, making it the latest version - const version = await secrets().secret('database.password').put(newPassword); - // [END snippet] -} diff --git a/examples/secrets/secrets-examples.test.ts b/examples/secrets/secrets-examples.test.ts deleted file mode 100644 index 2aa0e023..00000000 --- a/examples/secrets/secrets-examples.test.ts +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -import { secretsAccess } from './access'; -import { secretsLatest } from './latest'; -import { secretsPut } from './put'; -import { SecretServiceClient } from '@nitric/api/proto/secret/v1/secret_grpc_pb'; -import { - SecretAccessResponse, - SecretPutResponse, - SecretVersion, - Secret -} from '@nitric/api/proto/secret/v1/secret_pb'; - -const proto = SecretServiceClient.prototype; - -describe('test secrets snippets', () => { - beforeAll(() => { - jest.spyOn(proto, 'access').mockImplementation((request, callback: any) => { - const mockResponse = new SecretAccessResponse(); - const s = new Secret(); - s.setName('database.password'); - const sv = new SecretVersion(); - sv.setSecret(s); - sv.setVersion('1'); - - mockResponse.setSecretVersion(sv); - const encoder = new TextEncoder(); - - mockResponse.setValue(encoder.encode('test')); - - callback(null, mockResponse); - - return null as any; - }); - - jest.spyOn(proto, 'put').mockImplementation((request, callback: any) => { - const mockResponse = new SecretPutResponse(); - const s = new Secret(); - s.setName('test'); - const sv = new SecretVersion(); - sv.setSecret(s); - sv.setVersion('1'); - - mockResponse.setSecretVersion(sv); - - callback(null, mockResponse); - - return null as any; - }); - }); - - test('ensure all secrets snippets run', async () => { - await expect(secretsPut()).resolves.toEqual(undefined); - await expect(secretsLatest()).resolves.toEqual(undefined); - await expect(secretsAccess()).resolves.toEqual(undefined); - }); -}); diff --git a/examples/storage/delete.ts b/examples/storage/delete.ts deleted file mode 100644 index 90426440..00000000 --- a/examples/storage/delete.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { storage } from '@nitric/sdk'; -// [END import] - -export async function storageDelete() { - // [START snippet] - // Construct a new storage client with default settings - const sc = storage(); - - // Delete a file from a bucket - await sc.bucket('my-bucket').file('path/to/item').delete(); - // [END snippet] -} diff --git a/examples/storage/read.ts b/examples/storage/read.ts deleted file mode 100644 index 661dfb93..00000000 --- a/examples/storage/read.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { storage } from '@nitric/sdk'; -// [END import] - -export async function storageRead() { - // [START snippet] - // Construct a new storage client with default settings - const sc = storage(); - - // Read a byte array from a bucket - const bytes = await sc.bucket('my-bucket').file('path/to/item').read(); - // [END snippet] -} diff --git a/examples/storage/signed-url-read.ts b/examples/storage/signed-url-read.ts deleted file mode 100644 index 93684340..00000000 --- a/examples/storage/signed-url-read.ts +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { storage, FileMode } from '@nitric/sdk'; -// [END import] - -export async function storagePresignedUrlRead() { - // [START snippet] - // Construct a new storage client with default settings - const sc = storage(); - - // Get a signed url for reading a file - const url = await sc - .bucket('my-bucket') - .file('path/to/item') - .signUrl(FileMode.Read, { - // expiry in seconds - expiry: 3600, - }); - - return url; - // [END snippet] -} diff --git a/examples/storage/signed-url-write.ts b/examples/storage/signed-url-write.ts deleted file mode 100644 index 296d86f9..00000000 --- a/examples/storage/signed-url-write.ts +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { storage, FileMode } from '@nitric/sdk'; -// [END import] - -export async function storagePresignedUrlWrite() { - // [START snippet] - // Construct a new storage client with default settings - const sc = storage(); - - // Get a signed url for for uploading file - const url = await sc - .bucket('my-bucket') - .file('path/to/item') - .signUrl(FileMode.Write, { - // expiry in seconds - expiry: 3600, - }); - - console.log('Generated PUT signed URL:'); - console.log(url); - console.log('You can use this URL with any user agent, for example:'); - console.log( - "curl -X PUT -H 'Content-Type: application/octet-stream' " + - `--upload-file my-file '${url}'` - ); - - return url; - // [END snippet] -} diff --git a/examples/storage/storage-examples.test.ts b/examples/storage/storage-examples.test.ts deleted file mode 100644 index 85516a16..00000000 --- a/examples/storage/storage-examples.test.ts +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -import { StorageServiceClient } from '@nitric/api/proto/storage/v1/storage_grpc_pb'; -import { - StorageDeleteResponse, - StoragePreSignUrlResponse, - StorageReadResponse, - StorageWriteResponse, -} from '@nitric/api/proto/storage/v1/storage_pb'; - -import { storageDelete } from './delete'; -import { storageRead } from './read'; -import { storagePresignedUrlRead } from './signed-url-read'; -import { storagePresignedUrlWrite } from './signed-url-write'; -import { storageWrite } from './write'; - -const proto = StorageServiceClient.prototype; - -const CALLBACKFN = (response) => (_, cb: any) => cb(null, response); - -describe('test storage snippets', () => { - beforeAll(() => { - jest - .spyOn(proto, 'delete') - .mockImplementation(CALLBACKFN(new StorageDeleteResponse())); - jest - .spyOn(proto, 'read') - .mockImplementation(CALLBACKFN(new StorageReadResponse())); - jest - .spyOn(proto, 'write') - .mockImplementation(CALLBACKFN(new StorageWriteResponse())); - jest - .spyOn(proto, 'preSignUrl') - .mockImplementation(CALLBACKFN(new StoragePreSignUrlResponse())); - }); - - test('ensure all storage snippets run', async () => { - await expect(storageDelete()).resolves.toEqual(undefined); - await expect(storageRead()).resolves.toEqual(undefined); - await expect(storageWrite()).resolves.toEqual(undefined); - await expect(storagePresignedUrlRead()).resolves.toEqual(''); - await expect(storagePresignedUrlWrite()).resolves.toEqual(''); - }); -}); diff --git a/examples/storage/write.ts b/examples/storage/write.ts deleted file mode 100644 index e19297ae..00000000 --- a/examples/storage/write.ts +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2021, Nitric Technologies Pty Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// [START import] -import { storage } from '@nitric/sdk'; -// [END import] - -export async function storageWrite() { - // [START snippet] - // Construct a new storage client with default settings - const sc = storage(); - - // Example byte array - const contents = new Uint8Array(); - - // Write a byte array to a bucket - await sc.bucket('my-bucket').file('path/to/item').write(contents); - // [END snippet] -}